Skip to content

Commit 4110d39

Browse files
author
Roger Riggs
committedNov 25, 2024
8344865: SM cleanup in sun/reflect/annotation
Reviewed-by: liach, jpai
1 parent 1334191 commit 4110d39

File tree

4 files changed

+16
-49
lines changed

4 files changed

+16
-49
lines changed
 

‎src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import java.io.Serializable;
3232
import java.util.*;
3333
import java.util.stream.*;
34-
import java.security.AccessController;
35-
import java.security.PrivilegedAction;
3634

3735
/**
3836
* InvocationHandler for dynamic proxy implementation of Annotation.
@@ -481,16 +479,11 @@ private Method[] getMemberMethods() {
481479
return value;
482480
}
483481

484-
@SuppressWarnings("removal")
485482
private Method[] computeMemberMethods() {
486-
return AccessController.doPrivileged(
487-
new PrivilegedAction<Method[]>() {
488-
public Method[] run() {
489-
final Method[] methods = type.getDeclaredMethods();
490-
validateAnnotationMethods(methods);
491-
AccessibleObject.setAccessible(methods, true);
492-
return methods;
493-
}});
483+
final Method[] methods = type.getDeclaredMethods();
484+
validateAnnotationMethods(methods);
485+
AccessibleObject.setAccessible(methods, true);
486+
return methods;
494487
}
495488

496489
private transient volatile Method[] memberMethods;

‎src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,8 +31,7 @@
3131
import java.nio.ByteBuffer;
3232
import java.util.*;
3333
import java.util.function.Supplier;
34-
import java.security.AccessController;
35-
import java.security.PrivilegedAction;
34+
3635
import jdk.internal.reflect.ConstantPool;
3736

3837
import sun.reflect.generics.parser.SignatureParser;
@@ -292,16 +291,12 @@ private static Annotation parseAnnotation2(ByteBuffer buf,
292291
* Returns an annotation of the given type backed by the given
293292
* member {@literal ->} value map.
294293
*/
295-
@SuppressWarnings("removal")
296294
public static Annotation annotationForMap(final Class<? extends Annotation> type,
297295
final Map<String, Object> memberValues)
298296
{
299-
return AccessController.doPrivileged(new PrivilegedAction<Annotation>() {
300-
public Annotation run() {
301-
return (Annotation) Proxy.newProxyInstance(
302-
type.getClassLoader(), new Class<?>[] { type },
303-
new AnnotationInvocationHandler(type, memberValues));
304-
}});
297+
return (Annotation) Proxy.newProxyInstance(
298+
type.getClassLoader(), new Class<?>[] { type },
299+
new AnnotationInvocationHandler(type, memberValues));
305300
}
306301

307302
/**

‎src/java.base/share/classes/sun/reflect/annotation/AnnotationSupport.java

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,8 +27,6 @@
2727

2828
import java.lang.annotation.*;
2929
import java.lang.reflect.*;
30-
import java.security.AccessController;
31-
import java.security.PrivilegedAction;
3230
import java.util.ArrayList;
3331
import java.util.Arrays;
3432
import java.util.List;
@@ -181,7 +179,6 @@ public static <A extends Annotation> A[] getAssociatedAnnotations(
181179
/* Reflectively invoke the values-method of the given annotation
182180
* (container), cast it to an array of annotations and return the result.
183181
*/
184-
@SuppressWarnings("removal")
185182
private static <A extends Annotation> A[] getValueArray(Annotation container) {
186183
try {
187184
// According to JLS the container must have an array-valued value
@@ -225,19 +222,8 @@ private static <A extends Annotation> A[] getValueArray(Annotation container) {
225222
// Interface might not be public though
226223
final Method toInvoke;
227224
if (!Modifier.isPublic(iface.getModifiers())) {
228-
if (System.getSecurityManager() != null) {
229-
toInvoke = AccessController.doPrivileged(new PrivilegedAction<Method>() {
230-
@Override
231-
public Method run() {
232-
Method res = ReflectionFactory.getReflectionFactory().leafCopyMethod(m);
233-
res.setAccessible(true);
234-
return res;
235-
}
236-
});
237-
} else {
238-
toInvoke = ReflectionFactory.getReflectionFactory().leafCopyMethod(m);
239-
toInvoke.setAccessible(true);
240-
}
225+
toInvoke = ReflectionFactory.getReflectionFactory().leafCopyMethod(m);
226+
toInvoke.setAccessible(true);
241227
} else {
242228
toInvoke = m;
243229
}

‎src/java.base/share/classes/sun/reflect/annotation/AnnotationType.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,8 +28,7 @@
2828
import java.lang.annotation.*;
2929
import java.lang.reflect.*;
3030
import java.util.*;
31-
import java.security.AccessController;
32-
import java.security.PrivilegedAction;
31+
3332
import jdk.internal.access.SharedSecrets;
3433
import jdk.internal.access.JavaLangAccess;
3534

@@ -105,14 +104,8 @@ private AnnotationType(final Class<? extends Annotation> annotationClass) {
105104
if (!annotationClass.isAnnotation())
106105
throw new IllegalArgumentException("Not an annotation type");
107106

108-
@SuppressWarnings("removal")
109-
Method[] methods =
110-
AccessController.doPrivileged(new PrivilegedAction<>() {
111-
public Method[] run() {
112-
// Initialize memberTypes and defaultValues
113-
return annotationClass.getDeclaredMethods();
114-
}
115-
});
107+
// Initialize memberTypes and defaultValues
108+
Method[] methods = annotationClass.getDeclaredMethods();
116109

117110
memberTypes = new HashMap<>(methods.length+1, 1.0f);
118111
memberDefaults = new HashMap<>(0);

0 commit comments

Comments
 (0)
Please sign in to comment.