8344865: SM cleanup in sun/reflect/annotation
Reviewed-by: liach, jpai
This commit is contained in:
parent
133419177d
commit
4110d3925c
@ -31,8 +31,6 @@ import java.lang.reflect.*;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.*;
|
import java.util.stream.*;
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InvocationHandler for dynamic proxy implementation of Annotation.
|
* InvocationHandler for dynamic proxy implementation of Annotation.
|
||||||
@ -481,16 +479,11 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
private Method[] computeMemberMethods() {
|
private Method[] computeMemberMethods() {
|
||||||
return AccessController.doPrivileged(
|
final Method[] methods = type.getDeclaredMethods();
|
||||||
new PrivilegedAction<Method[]>() {
|
validateAnnotationMethods(methods);
|
||||||
public Method[] run() {
|
AccessibleObject.setAccessible(methods, true);
|
||||||
final Method[] methods = type.getDeclaredMethods();
|
return methods;
|
||||||
validateAnnotationMethods(methods);
|
|
||||||
AccessibleObject.setAccessible(methods, true);
|
|
||||||
return methods;
|
|
||||||
}});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private transient volatile Method[] memberMethods;
|
private transient volatile Method[] memberMethods;
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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.nio.ByteBuffer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
import jdk.internal.reflect.ConstantPool;
|
import jdk.internal.reflect.ConstantPool;
|
||||||
|
|
||||||
import sun.reflect.generics.parser.SignatureParser;
|
import sun.reflect.generics.parser.SignatureParser;
|
||||||
@ -292,16 +291,12 @@ public class AnnotationParser {
|
|||||||
* Returns an annotation of the given type backed by the given
|
* Returns an annotation of the given type backed by the given
|
||||||
* member {@literal ->} value map.
|
* member {@literal ->} value map.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public static Annotation annotationForMap(final Class<? extends Annotation> type,
|
public static Annotation annotationForMap(final Class<? extends Annotation> type,
|
||||||
final Map<String, Object> memberValues)
|
final Map<String, Object> memberValues)
|
||||||
{
|
{
|
||||||
return AccessController.doPrivileged(new PrivilegedAction<Annotation>() {
|
return (Annotation) Proxy.newProxyInstance(
|
||||||
public Annotation run() {
|
type.getClassLoader(), new Class<?>[] { type },
|
||||||
return (Annotation) Proxy.newProxyInstance(
|
new AnnotationInvocationHandler(type, memberValues));
|
||||||
type.getClassLoader(), new Class<?>[] { type },
|
|
||||||
new AnnotationInvocationHandler(type, memberValues));
|
|
||||||
}});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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.annotation.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -181,7 +179,6 @@ public final class AnnotationSupport {
|
|||||||
/* Reflectively invoke the values-method of the given annotation
|
/* Reflectively invoke the values-method of the given annotation
|
||||||
* (container), cast it to an array of annotations and return the result.
|
* (container), cast it to an array of annotations and return the result.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
private static <A extends Annotation> A[] getValueArray(Annotation container) {
|
private static <A extends Annotation> A[] getValueArray(Annotation container) {
|
||||||
try {
|
try {
|
||||||
// According to JLS the container must have an array-valued value
|
// 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
|
// Interface might not be public though
|
||||||
final Method toInvoke;
|
final Method toInvoke;
|
||||||
if (!Modifier.isPublic(iface.getModifiers())) {
|
if (!Modifier.isPublic(iface.getModifiers())) {
|
||||||
if (System.getSecurityManager() != null) {
|
toInvoke = ReflectionFactory.getReflectionFactory().leafCopyMethod(m);
|
||||||
toInvoke = AccessController.doPrivileged(new PrivilegedAction<Method>() {
|
toInvoke.setAccessible(true);
|
||||||
@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 {
|
} else {
|
||||||
toInvoke = m;
|
toInvoke = m;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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.annotation.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedAction;
|
|
||||||
import jdk.internal.access.SharedSecrets;
|
import jdk.internal.access.SharedSecrets;
|
||||||
import jdk.internal.access.JavaLangAccess;
|
import jdk.internal.access.JavaLangAccess;
|
||||||
|
|
||||||
@ -105,14 +104,8 @@ public class AnnotationType {
|
|||||||
if (!annotationClass.isAnnotation())
|
if (!annotationClass.isAnnotation())
|
||||||
throw new IllegalArgumentException("Not an annotation type");
|
throw new IllegalArgumentException("Not an annotation type");
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
// Initialize memberTypes and defaultValues
|
||||||
Method[] methods =
|
Method[] methods = annotationClass.getDeclaredMethods();
|
||||||
AccessController.doPrivileged(new PrivilegedAction<>() {
|
|
||||||
public Method[] run() {
|
|
||||||
// Initialize memberTypes and defaultValues
|
|
||||||
return annotationClass.getDeclaredMethods();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
memberTypes = new HashMap<>(methods.length+1, 1.0f);
|
memberTypes = new HashMap<>(methods.length+1, 1.0f);
|
||||||
memberDefaults = new HashMap<>(0);
|
memberDefaults = new HashMap<>(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user