From 4110d3925c8bfc3256b01d835faa111c2c21b8db Mon Sep 17 00:00:00 2001 From: Roger Riggs Date: Mon, 25 Nov 2024 14:34:27 +0000 Subject: [PATCH] 8344865: SM cleanup in sun/reflect/annotation Reviewed-by: liach, jpai --- .../AnnotationInvocationHandler.java | 15 ++++---------- .../reflect/annotation/AnnotationParser.java | 15 +++++--------- .../reflect/annotation/AnnotationSupport.java | 20 +++---------------- .../reflect/annotation/AnnotationType.java | 15 ++++---------- 4 files changed, 16 insertions(+), 49 deletions(-) diff --git a/src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java b/src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java index 16869b019e7..fcee641458e 100644 --- a/src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java +++ b/src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java @@ -31,8 +31,6 @@ import java.lang.reflect.*; import java.io.Serializable; import java.util.*; import java.util.stream.*; -import java.security.AccessController; -import java.security.PrivilegedAction; /** * InvocationHandler for dynamic proxy implementation of Annotation. @@ -481,16 +479,11 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable { return value; } - @SuppressWarnings("removal") private Method[] computeMemberMethods() { - return AccessController.doPrivileged( - new PrivilegedAction() { - public Method[] run() { - final Method[] methods = type.getDeclaredMethods(); - validateAnnotationMethods(methods); - AccessibleObject.setAccessible(methods, true); - return methods; - }}); + final Method[] methods = type.getDeclaredMethods(); + validateAnnotationMethods(methods); + AccessibleObject.setAccessible(methods, true); + return methods; } private transient volatile Method[] memberMethods; diff --git a/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java b/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java index 1e8c5401231..e5a3e636c2c 100644 --- a/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java +++ b/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,8 +31,7 @@ import java.nio.BufferUnderflowException; import java.nio.ByteBuffer; import java.util.*; import java.util.function.Supplier; -import java.security.AccessController; -import java.security.PrivilegedAction; + import jdk.internal.reflect.ConstantPool; import sun.reflect.generics.parser.SignatureParser; @@ -292,16 +291,12 @@ public class AnnotationParser { * Returns an annotation of the given type backed by the given * member {@literal ->} value map. */ - @SuppressWarnings("removal") public static Annotation annotationForMap(final Class type, final Map memberValues) { - return AccessController.doPrivileged(new PrivilegedAction() { - public Annotation run() { - return (Annotation) Proxy.newProxyInstance( - type.getClassLoader(), new Class[] { type }, - new AnnotationInvocationHandler(type, memberValues)); - }}); + return (Annotation) Proxy.newProxyInstance( + type.getClassLoader(), new Class[] { type }, + new AnnotationInvocationHandler(type, memberValues)); } /** diff --git a/src/java.base/share/classes/sun/reflect/annotation/AnnotationSupport.java b/src/java.base/share/classes/sun/reflect/annotation/AnnotationSupport.java index a70ffafd363..fd76eedfbcd 100644 --- a/src/java.base/share/classes/sun/reflect/annotation/AnnotationSupport.java +++ b/src/java.base/share/classes/sun/reflect/annotation/AnnotationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,8 +27,6 @@ package sun.reflect.annotation; import java.lang.annotation.*; import java.lang.reflect.*; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -181,7 +179,6 @@ public final class AnnotationSupport { /* Reflectively invoke the values-method of the given annotation * (container), cast it to an array of annotations and return the result. */ - @SuppressWarnings("removal") private static A[] getValueArray(Annotation container) { try { // According to JLS the container must have an array-valued value @@ -225,19 +222,8 @@ public final class AnnotationSupport { // Interface might not be public though final Method toInvoke; if (!Modifier.isPublic(iface.getModifiers())) { - if (System.getSecurityManager() != null) { - toInvoke = AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Method run() { - Method res = ReflectionFactory.getReflectionFactory().leafCopyMethod(m); - res.setAccessible(true); - return res; - } - }); - } else { - toInvoke = ReflectionFactory.getReflectionFactory().leafCopyMethod(m); - toInvoke.setAccessible(true); - } + toInvoke = ReflectionFactory.getReflectionFactory().leafCopyMethod(m); + toInvoke.setAccessible(true); } else { toInvoke = m; } diff --git a/src/java.base/share/classes/sun/reflect/annotation/AnnotationType.java b/src/java.base/share/classes/sun/reflect/annotation/AnnotationType.java index 89aff8a954a..3a4bd80b014 100644 --- a/src/java.base/share/classes/sun/reflect/annotation/AnnotationType.java +++ b/src/java.base/share/classes/sun/reflect/annotation/AnnotationType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,8 +28,7 @@ package sun.reflect.annotation; import java.lang.annotation.*; import java.lang.reflect.*; import java.util.*; -import java.security.AccessController; -import java.security.PrivilegedAction; + import jdk.internal.access.SharedSecrets; import jdk.internal.access.JavaLangAccess; @@ -105,14 +104,8 @@ public class AnnotationType { if (!annotationClass.isAnnotation()) throw new IllegalArgumentException("Not an annotation type"); - @SuppressWarnings("removal") - Method[] methods = - AccessController.doPrivileged(new PrivilegedAction<>() { - public Method[] run() { - // Initialize memberTypes and defaultValues - return annotationClass.getDeclaredMethods(); - } - }); + // Initialize memberTypes and defaultValues + Method[] methods = annotationClass.getDeclaredMethods(); memberTypes = new HashMap<>(methods.length+1, 1.0f); memberDefaults = new HashMap<>(0);