mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8202113: Reflection API is causing caller classes to leak
Reviewed-by: alanb, plevart
This commit is contained in:
parent
8af434d695
commit
0e1bd1f99d
11 changed files with 434 additions and 16 deletions
|
@ -564,7 +564,6 @@ public class AccessibleObject implements AnnotatedElement {
|
|||
throw new AssertionError("All subclasses should override this method");
|
||||
}
|
||||
|
||||
|
||||
// Shared access checking logic.
|
||||
|
||||
// For non-public members or members in package-private classes,
|
||||
|
@ -674,4 +673,13 @@ public class AccessibleObject implements AnnotatedElement {
|
|||
}
|
||||
return printStackWhenAccessFails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root AccessibleObject; or null if this object is the root.
|
||||
*
|
||||
* All subclasses override this method.
|
||||
*/
|
||||
AccessibleObject getRoot() {
|
||||
throw new InternalError();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,11 +103,8 @@ public final class Constructor<T> extends Executable {
|
|||
// occur in annotation code.
|
||||
private Constructor<T> root;
|
||||
|
||||
/**
|
||||
* Used by Excecutable for annotation sharing.
|
||||
*/
|
||||
@Override
|
||||
Executable getRoot() {
|
||||
Constructor<T> getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,11 +55,6 @@ public abstract class Executable extends AccessibleObject
|
|||
*/
|
||||
abstract byte[] getAnnotationBytes();
|
||||
|
||||
/**
|
||||
* Accessor method to allow code sharing
|
||||
*/
|
||||
abstract Executable getRoot();
|
||||
|
||||
/**
|
||||
* Does the Executable have generic information.
|
||||
*/
|
||||
|
@ -602,7 +597,7 @@ public abstract class Executable extends AccessibleObject
|
|||
if ((declAnnos = declaredAnnotations) == null) {
|
||||
synchronized (this) {
|
||||
if ((declAnnos = declaredAnnotations) == null) {
|
||||
Executable root = getRoot();
|
||||
Executable root = (Executable)getRoot();
|
||||
if (root != null) {
|
||||
declAnnos = root.declaredAnnotations();
|
||||
} else {
|
||||
|
|
|
@ -1128,6 +1128,11 @@ class Field extends AccessibleObject implements Member {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Field getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NullPointerException {@inheritDoc}
|
||||
* @since 1.5
|
||||
|
|
|
@ -198,11 +198,8 @@ public final class Method extends Executable {
|
|||
checkCanSetAccessible(caller, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by Excecutable for annotation sharing.
|
||||
*/
|
||||
@Override
|
||||
Executable getRoot() {
|
||||
Method getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
|
|
|
@ -154,4 +154,9 @@ class ReflectAccess implements jdk.internal.reflect.LangReflectAccess {
|
|||
public <T> Constructor<T> copyConstructor(Constructor<T> arg) {
|
||||
return arg.copy();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends AccessibleObject> T getRoot(T obj) {
|
||||
return (T) obj.getRoot();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue