8344865: SM cleanup in sun/reflect/annotation

Reviewed-by: liach, jpai
This commit is contained in:
Roger Riggs 2024-11-25 14:34:27 +00:00
parent 133419177d
commit 4110d3925c
4 changed files with 16 additions and 49 deletions

View File

@ -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<Method[]>() {
public Method[] run() {
final Method[] methods = type.getDeclaredMethods();
validateAnnotationMethods(methods);
AccessibleObject.setAccessible(methods, true);
return methods;
}});
}
private transient volatile Method[] memberMethods;

View File

@ -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<? extends Annotation> type,
final Map<String, Object> memberValues)
{
return AccessController.doPrivileged(new PrivilegedAction<Annotation>() {
public Annotation run() {
return (Annotation) Proxy.newProxyInstance(
type.getClassLoader(), new Class<?>[] { type },
new AnnotationInvocationHandler(type, memberValues));
}});
}
/**

View File

@ -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 extends Annotation> 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<Method>() {
@Override
public Method run() {
Method res = ReflectionFactory.getReflectionFactory().leafCopyMethod(m);
res.setAccessible(true);
return res;
}
});
} else {
toInvoke = ReflectionFactory.getReflectionFactory().leafCopyMethod(m);
toInvoke.setAccessible(true);
}
} else {
toInvoke = m;
}

View File

@ -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();
}
});
Method[] methods = annotationClass.getDeclaredMethods();
memberTypes = new HashMap<>(methods.length+1, 1.0f);
memberDefaults = new HashMap<>(0);