5062288: (reflect) Core reflection uses raw types when it could be using wildcards
Reviewed-by: alanb
This commit is contained in:
parent
9f6fbc5544
commit
bd9e7da356
@ -265,7 +265,7 @@ public final
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Called after security checks have been made. */
|
/** Called after security checks have been made. */
|
||||||
private static native Class forName0(String name, boolean initialize,
|
private static native Class<?> forName0(String name, boolean initialize,
|
||||||
ClassLoader loader)
|
ClassLoader loader)
|
||||||
throws ClassNotFoundException;
|
throws ClassNotFoundException;
|
||||||
|
|
||||||
@ -339,7 +339,7 @@ public final
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Class[] empty = {};
|
Class<?>[] empty = {};
|
||||||
final Constructor<T> c = getConstructor0(empty, Member.DECLARED);
|
final Constructor<T> c = getConstructor0(empty, Member.DECLARED);
|
||||||
// Disable accessibility checks on the constructor
|
// Disable accessibility checks on the constructor
|
||||||
// since we have to do the security check here anyway
|
// since we have to do the security check here anyway
|
||||||
@ -361,7 +361,7 @@ public final
|
|||||||
// Security check (same as in java.lang.reflect.Constructor)
|
// Security check (same as in java.lang.reflect.Constructor)
|
||||||
int modifiers = tmpConstructor.getModifiers();
|
int modifiers = tmpConstructor.getModifiers();
|
||||||
if (!Reflection.quickCheckMemberAccess(this, modifiers)) {
|
if (!Reflection.quickCheckMemberAccess(this, modifiers)) {
|
||||||
Class caller = Reflection.getCallerClass(3);
|
Class<?> caller = Reflection.getCallerClass(3);
|
||||||
if (newInstanceCallerCache != caller) {
|
if (newInstanceCallerCache != caller) {
|
||||||
Reflection.ensureMemberAccess(caller, this, null, modifiers);
|
Reflection.ensureMemberAccess(caller, this, null, modifiers);
|
||||||
newInstanceCallerCache = caller;
|
newInstanceCallerCache = caller;
|
||||||
@ -377,7 +377,7 @@ public final
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private volatile transient Constructor<T> cachedConstructor;
|
private volatile transient Constructor<T> cachedConstructor;
|
||||||
private volatile transient Class newInstanceCallerCache;
|
private volatile transient Class<?> newInstanceCallerCache;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -638,7 +638,7 @@ public final
|
|||||||
if (getGenericSignature() != null)
|
if (getGenericSignature() != null)
|
||||||
return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters();
|
return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters();
|
||||||
else
|
else
|
||||||
return (TypeVariable<Class<T>>[])new TypeVariable[0];
|
return (TypeVariable<Class<T>>[])new TypeVariable<?>[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -901,7 +901,7 @@ public final
|
|||||||
|
|
||||||
MethodRepository typeInfo = MethodRepository.make(enclosingInfo.getDescriptor(),
|
MethodRepository typeInfo = MethodRepository.make(enclosingInfo.getDescriptor(),
|
||||||
getFactory());
|
getFactory());
|
||||||
Class returnType = toClass(typeInfo.getReturnType());
|
Class<?> returnType = toClass(typeInfo.getReturnType());
|
||||||
Type [] parameterTypes = typeInfo.getParameterTypes();
|
Type [] parameterTypes = typeInfo.getParameterTypes();
|
||||||
Class<?>[] parameterClasses = new Class<?>[parameterTypes.length];
|
Class<?>[] parameterClasses = new Class<?>[parameterTypes.length];
|
||||||
|
|
||||||
@ -996,12 +996,12 @@ public final
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class toClass(Type o) {
|
private static Class<?> toClass(Type o) {
|
||||||
if (o instanceof GenericArrayType)
|
if (o instanceof GenericArrayType)
|
||||||
return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
|
return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
|
||||||
0)
|
0)
|
||||||
.getClass();
|
.getClass();
|
||||||
return (Class)o;
|
return (Class<?>)o;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1042,7 +1042,7 @@ public final
|
|||||||
* Loop over all declared constructors; match number
|
* Loop over all declared constructors; match number
|
||||||
* of and type of parameters.
|
* of and type of parameters.
|
||||||
*/
|
*/
|
||||||
for(Constructor c: enclosingInfo.getEnclosingClass().getDeclaredConstructors()) {
|
for(Constructor<?> c: enclosingInfo.getEnclosingClass().getDeclaredConstructors()) {
|
||||||
Class<?>[] candidateParamClasses = c.getParameterTypes();
|
Class<?>[] candidateParamClasses = c.getParameterTypes();
|
||||||
if (candidateParamClasses.length == parameterClasses.length) {
|
if (candidateParamClasses.length == parameterClasses.length) {
|
||||||
boolean matches = true;
|
boolean matches = true;
|
||||||
@ -1304,12 +1304,12 @@ public final
|
|||||||
// has already been ok'd by the SecurityManager.
|
// has already been ok'd by the SecurityManager.
|
||||||
|
|
||||||
return java.security.AccessController.doPrivileged(
|
return java.security.AccessController.doPrivileged(
|
||||||
new java.security.PrivilegedAction<Class[]>() {
|
new java.security.PrivilegedAction<Class<?>[]>() {
|
||||||
public Class[] run() {
|
public Class[] run() {
|
||||||
List<Class> list = new ArrayList<Class>();
|
List<Class<?>> list = new ArrayList<Class<?>>();
|
||||||
Class currentClass = Class.this;
|
Class<?> currentClass = Class.this;
|
||||||
while (currentClass != null) {
|
while (currentClass != null) {
|
||||||
Class[] members = currentClass.getDeclaredClasses();
|
Class<?>[] members = currentClass.getDeclaredClasses();
|
||||||
for (int i = 0; i < members.length; i++) {
|
for (int i = 0; i < members.length; i++) {
|
||||||
if (Modifier.isPublic(members[i].getModifiers())) {
|
if (Modifier.isPublic(members[i].getModifiers())) {
|
||||||
list.add(members[i]);
|
list.add(members[i]);
|
||||||
@ -2191,7 +2191,7 @@ public final
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
if (!name.startsWith("/")) {
|
if (!name.startsWith("/")) {
|
||||||
Class c = this;
|
Class<?> c = this;
|
||||||
while (c.isArray()) {
|
while (c.isArray()) {
|
||||||
c = c.getComponentType();
|
c = c.getComponentType();
|
||||||
}
|
}
|
||||||
@ -2565,12 +2565,12 @@ public final
|
|||||||
// out concrete implementations inherited from superclasses at
|
// out concrete implementations inherited from superclasses at
|
||||||
// the end.
|
// the end.
|
||||||
MethodArray inheritedMethods = new MethodArray();
|
MethodArray inheritedMethods = new MethodArray();
|
||||||
Class[] interfaces = getInterfaces();
|
Class<?>[] interfaces = getInterfaces();
|
||||||
for (int i = 0; i < interfaces.length; i++) {
|
for (int i = 0; i < interfaces.length; i++) {
|
||||||
inheritedMethods.addAll(interfaces[i].privateGetPublicMethods());
|
inheritedMethods.addAll(interfaces[i].privateGetPublicMethods());
|
||||||
}
|
}
|
||||||
if (!isInterface()) {
|
if (!isInterface()) {
|
||||||
Class c = getSuperclass();
|
Class<?> c = getSuperclass();
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
MethodArray supers = new MethodArray();
|
MethodArray supers = new MethodArray();
|
||||||
supers.addAll(c.privateGetPublicMethods());
|
supers.addAll(c.privateGetPublicMethods());
|
||||||
@ -2632,16 +2632,16 @@ public final
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
// Direct superinterfaces, recursively
|
// Direct superinterfaces, recursively
|
||||||
Class[] interfaces = getInterfaces();
|
Class<?>[] interfaces = getInterfaces();
|
||||||
for (int i = 0; i < interfaces.length; i++) {
|
for (int i = 0; i < interfaces.length; i++) {
|
||||||
Class c = interfaces[i];
|
Class<?> c = interfaces[i];
|
||||||
if ((res = c.getField0(name)) != null) {
|
if ((res = c.getField0(name)) != null) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Direct superclass, recursively
|
// Direct superclass, recursively
|
||||||
if (!isInterface()) {
|
if (!isInterface()) {
|
||||||
Class c = getSuperclass();
|
Class<?> c = getSuperclass();
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
if ((res = c.getField0(name)) != null) {
|
if ((res = c.getField0(name)) != null) {
|
||||||
return res;
|
return res;
|
||||||
@ -2653,7 +2653,7 @@ public final
|
|||||||
|
|
||||||
private static Method searchMethods(Method[] methods,
|
private static Method searchMethods(Method[] methods,
|
||||||
String name,
|
String name,
|
||||||
Class[] parameterTypes)
|
Class<?>[] parameterTypes)
|
||||||
{
|
{
|
||||||
Method res = null;
|
Method res = null;
|
||||||
String internedName = name.intern();
|
String internedName = name.intern();
|
||||||
@ -2670,7 +2670,7 @@ public final
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Method getMethod0(String name, Class[] parameterTypes) {
|
private Method getMethod0(String name, Class<?>[] parameterTypes) {
|
||||||
// Note: the intent is that the search algorithm this routine
|
// Note: the intent is that the search algorithm this routine
|
||||||
// uses be equivalent to the ordering imposed by
|
// uses be equivalent to the ordering imposed by
|
||||||
// privateGetPublicMethods(). It fetches only the declared
|
// privateGetPublicMethods(). It fetches only the declared
|
||||||
@ -2687,7 +2687,7 @@ public final
|
|||||||
}
|
}
|
||||||
// Search superclass's methods
|
// Search superclass's methods
|
||||||
if (!isInterface()) {
|
if (!isInterface()) {
|
||||||
Class c = getSuperclass();
|
Class<? super T> c = getSuperclass();
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
if ((res = c.getMethod0(name, parameterTypes)) != null) {
|
if ((res = c.getMethod0(name, parameterTypes)) != null) {
|
||||||
return res;
|
return res;
|
||||||
@ -2695,9 +2695,9 @@ public final
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Search superinterfaces' methods
|
// Search superinterfaces' methods
|
||||||
Class[] interfaces = getInterfaces();
|
Class<?>[] interfaces = getInterfaces();
|
||||||
for (int i = 0; i < interfaces.length; i++) {
|
for (int i = 0; i < interfaces.length; i++) {
|
||||||
Class c = interfaces[i];
|
Class<?> c = interfaces[i];
|
||||||
if ((res = c.getMethod0(name, parameterTypes)) != null) {
|
if ((res = c.getMethod0(name, parameterTypes)) != null) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -2706,7 +2706,7 @@ public final
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Constructor<T> getConstructor0(Class[] parameterTypes,
|
private Constructor<T> getConstructor0(Class<?>[] parameterTypes,
|
||||||
int which) throws NoSuchMethodException
|
int which) throws NoSuchMethodException
|
||||||
{
|
{
|
||||||
Constructor<T>[] constructors = privateGetDeclaredConstructors((which == Member.PUBLIC));
|
Constructor<T>[] constructors = privateGetDeclaredConstructors((which == Member.PUBLIC));
|
||||||
@ -2775,9 +2775,9 @@ public final
|
|||||||
private native Field[] getDeclaredFields0(boolean publicOnly);
|
private native Field[] getDeclaredFields0(boolean publicOnly);
|
||||||
private native Method[] getDeclaredMethods0(boolean publicOnly);
|
private native Method[] getDeclaredMethods0(boolean publicOnly);
|
||||||
private native Constructor<T>[] getDeclaredConstructors0(boolean publicOnly);
|
private native Constructor<T>[] getDeclaredConstructors0(boolean publicOnly);
|
||||||
private native Class[] getDeclaredClasses0();
|
private native Class<?>[] getDeclaredClasses0();
|
||||||
|
|
||||||
private static String argumentTypesToString(Class[] argTypes) {
|
private static String argumentTypesToString(Class<?>[] argTypes) {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
buf.append("(");
|
buf.append("(");
|
||||||
if (argTypes != null) {
|
if (argTypes != null) {
|
||||||
@ -2785,7 +2785,7 @@ public final
|
|||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
buf.append(", ");
|
buf.append(", ");
|
||||||
}
|
}
|
||||||
Class c = argTypes[i];
|
Class<?> c = argTypes[i];
|
||||||
buf.append((c == null) ? "null" : c.getName());
|
buf.append((c == null) ? "null" : c.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2858,7 +2858,7 @@ public final
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves the desired assertion status of this class from the VM
|
// Retrieves the desired assertion status of this class from the VM
|
||||||
private static native boolean desiredAssertionStatus0(Class clazz);
|
private static native boolean desiredAssertionStatus0(Class<?> clazz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if and only if this class was declared as an enum in the
|
* Returns true if and only if this class was declared as an enum in the
|
||||||
@ -2979,7 +2979,7 @@ public final
|
|||||||
getName() + " is not an enum type");
|
getName() + " is not an enum type");
|
||||||
Map<String, T> m = new HashMap<String, T>(2 * universe.length);
|
Map<String, T> m = new HashMap<String, T>(2 * universe.length);
|
||||||
for (T constant : universe)
|
for (T constant : universe)
|
||||||
m.put(((Enum)constant).name(), constant);
|
m.put(((Enum<?>)constant).name(), constant);
|
||||||
enumConstantDirectory = m;
|
enumConstantDirectory = m;
|
||||||
}
|
}
|
||||||
return enumConstantDirectory;
|
return enumConstantDirectory;
|
||||||
@ -3077,8 +3077,8 @@ public final
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Annotations cache
|
// Annotations cache
|
||||||
private transient Map<Class, Annotation> annotations;
|
private transient Map<Class<? extends Annotation>, Annotation> annotations;
|
||||||
private transient Map<Class, Annotation> declaredAnnotations;
|
private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
|
||||||
|
|
||||||
private synchronized void initAnnotationsIfNecessary() {
|
private synchronized void initAnnotationsIfNecessary() {
|
||||||
clearCachesOnClassRedefinition();
|
clearCachesOnClassRedefinition();
|
||||||
@ -3090,10 +3090,10 @@ public final
|
|||||||
if (superClass == null) {
|
if (superClass == null) {
|
||||||
annotations = declaredAnnotations;
|
annotations = declaredAnnotations;
|
||||||
} else {
|
} else {
|
||||||
annotations = new HashMap<Class, Annotation>();
|
annotations = new HashMap<Class<? extends Annotation>, Annotation>();
|
||||||
superClass.initAnnotationsIfNecessary();
|
superClass.initAnnotationsIfNecessary();
|
||||||
for (Map.Entry<Class, Annotation> e : superClass.annotations.entrySet()) {
|
for (Map.Entry<Class<? extends Annotation>, Annotation> e : superClass.annotations.entrySet()) {
|
||||||
Class annotationClass = e.getKey();
|
Class<? extends Annotation> annotationClass = e.getKey();
|
||||||
if (AnnotationType.getInstance(annotationClass).isInherited())
|
if (AnnotationType.getInstance(annotationClass).isInherited())
|
||||||
annotations.put(annotationClass, e.getValue());
|
annotations.put(annotationClass, e.getValue());
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ public class Package implements java.lang.reflect.AnnotatedElement {
|
|||||||
* @param class the class to get the package of.
|
* @param class the class to get the package of.
|
||||||
* @return the package of the class. It may be null if no package
|
* @return the package of the class. It may be null if no package
|
||||||
* information is available from the archive or codebase. */
|
* information is available from the archive or codebase. */
|
||||||
static Package getPackage(Class c) {
|
static Package getPackage(Class<?> c) {
|
||||||
String name = c.getName();
|
String name = c.getName();
|
||||||
int i = name.lastIndexOf('.');
|
int i = name.lastIndexOf('.');
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
|
@ -131,7 +131,7 @@ public class AccessibleObject implements AnnotatedElement {
|
|||||||
throws SecurityException
|
throws SecurityException
|
||||||
{
|
{
|
||||||
if (obj instanceof Constructor && flag == true) {
|
if (obj instanceof Constructor && flag == true) {
|
||||||
Constructor c = (Constructor)obj;
|
Constructor<?> c = (Constructor<?>)obj;
|
||||||
if (c.getDeclaringClass() == Class.class) {
|
if (c.getDeclaringClass() == Class.class) {
|
||||||
throw new SecurityException("Can not make a java.lang.Class" +
|
throw new SecurityException("Can not make a java.lang.Class" +
|
||||||
" constructor accessible");
|
" constructor accessible");
|
||||||
|
@ -64,8 +64,8 @@ public final
|
|||||||
|
|
||||||
private Class<T> clazz;
|
private Class<T> clazz;
|
||||||
private int slot;
|
private int slot;
|
||||||
private Class[] parameterTypes;
|
private Class<?>[] parameterTypes;
|
||||||
private Class[] exceptionTypes;
|
private Class<?>[] exceptionTypes;
|
||||||
private int modifiers;
|
private int modifiers;
|
||||||
// Generics and annotations support
|
// Generics and annotations support
|
||||||
private transient String signature;
|
private transient String signature;
|
||||||
@ -80,7 +80,7 @@ public final
|
|||||||
// always succeed (it is not affected by the granting or revoking
|
// always succeed (it is not affected by the granting or revoking
|
||||||
// of permissions); we speed up the check in the common case by
|
// of permissions); we speed up the check in the common case by
|
||||||
// remembering the last Class for which the check succeeded.
|
// remembering the last Class for which the check succeeded.
|
||||||
private volatile Class securityCheckCache;
|
private volatile Class<?> securityCheckCache;
|
||||||
|
|
||||||
// Generics infrastructure
|
// Generics infrastructure
|
||||||
// Accessor for factory
|
// Accessor for factory
|
||||||
@ -113,8 +113,8 @@ public final
|
|||||||
* package via sun.reflect.LangReflectAccess.
|
* package via sun.reflect.LangReflectAccess.
|
||||||
*/
|
*/
|
||||||
Constructor(Class<T> declaringClass,
|
Constructor(Class<T> declaringClass,
|
||||||
Class[] parameterTypes,
|
Class<?>[] parameterTypes,
|
||||||
Class[] checkedExceptions,
|
Class<?>[] checkedExceptions,
|
||||||
int modifiers,
|
int modifiers,
|
||||||
int slot,
|
int slot,
|
||||||
String signature,
|
String signature,
|
||||||
@ -307,11 +307,11 @@ public final
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj != null && obj instanceof Constructor) {
|
if (obj != null && obj instanceof Constructor) {
|
||||||
Constructor other = (Constructor)obj;
|
Constructor<?> other = (Constructor<?>)obj;
|
||||||
if (getDeclaringClass() == other.getDeclaringClass()) {
|
if (getDeclaringClass() == other.getDeclaringClass()) {
|
||||||
/* Avoid unnecessary cloning */
|
/* Avoid unnecessary cloning */
|
||||||
Class[] params1 = parameterTypes;
|
Class<?>[] params1 = parameterTypes;
|
||||||
Class[] params2 = other.parameterTypes;
|
Class<?>[] params2 = other.parameterTypes;
|
||||||
if (params1.length == params2.length) {
|
if (params1.length == params2.length) {
|
||||||
for (int i = 0; i < params1.length; i++) {
|
for (int i = 0; i < params1.length; i++) {
|
||||||
if (params1[i] != params2[i])
|
if (params1[i] != params2[i])
|
||||||
@ -357,14 +357,14 @@ public final
|
|||||||
}
|
}
|
||||||
sb.append(Field.getTypeName(getDeclaringClass()));
|
sb.append(Field.getTypeName(getDeclaringClass()));
|
||||||
sb.append("(");
|
sb.append("(");
|
||||||
Class[] params = parameterTypes; // avoid clone
|
Class<?>[] params = parameterTypes; // avoid clone
|
||||||
for (int j = 0; j < params.length; j++) {
|
for (int j = 0; j < params.length; j++) {
|
||||||
sb.append(Field.getTypeName(params[j]));
|
sb.append(Field.getTypeName(params[j]));
|
||||||
if (j < (params.length - 1))
|
if (j < (params.length - 1))
|
||||||
sb.append(",");
|
sb.append(",");
|
||||||
}
|
}
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
Class[] exceptions = exceptionTypes; // avoid clone
|
Class<?>[] exceptions = exceptionTypes; // avoid clone
|
||||||
if (exceptions.length > 0) {
|
if (exceptions.length > 0) {
|
||||||
sb.append(" throws ");
|
sb.append(" throws ");
|
||||||
for (int k = 0; k < exceptions.length; k++) {
|
for (int k = 0; k < exceptions.length; k++) {
|
||||||
@ -452,7 +452,7 @@ public final
|
|||||||
sb.append(" throws ");
|
sb.append(" throws ");
|
||||||
for (int k = 0; k < exceptions.length; k++) {
|
for (int k = 0; k < exceptions.length; k++) {
|
||||||
sb.append((exceptions[k] instanceof Class)?
|
sb.append((exceptions[k] instanceof Class)?
|
||||||
((Class)exceptions[k]).getName():
|
((Class<?>)exceptions[k]).getName():
|
||||||
exceptions[k].toString());
|
exceptions[k].toString());
|
||||||
if (k < (exceptions.length - 1))
|
if (k < (exceptions.length - 1))
|
||||||
sb.append(",");
|
sb.append(",");
|
||||||
@ -518,7 +518,7 @@ public final
|
|||||||
{
|
{
|
||||||
if (!override) {
|
if (!override) {
|
||||||
if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
|
if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
|
||||||
Class caller = Reflection.getCallerClass(2);
|
Class<?> caller = Reflection.getCallerClass(2);
|
||||||
if (securityCheckCache != caller) {
|
if (securityCheckCache != caller) {
|
||||||
Reflection.ensureMemberAccess(caller, clazz, null, modifiers);
|
Reflection.ensureMemberAccess(caller, clazz, null, modifiers);
|
||||||
securityCheckCache = caller;
|
securityCheckCache = caller;
|
||||||
@ -625,9 +625,9 @@ public final
|
|||||||
return AnnotationParser.toArray(declaredAnnotations());
|
return AnnotationParser.toArray(declaredAnnotations());
|
||||||
}
|
}
|
||||||
|
|
||||||
private transient Map<Class, Annotation> declaredAnnotations;
|
private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
|
||||||
|
|
||||||
private synchronized Map<Class, Annotation> declaredAnnotations() {
|
private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
|
||||||
if (declaredAnnotations == null) {
|
if (declaredAnnotations == null) {
|
||||||
declaredAnnotations = AnnotationParser.parseAnnotations(
|
declaredAnnotations = AnnotationParser.parseAnnotations(
|
||||||
annotations, sun.misc.SharedSecrets.getJavaLangAccess().
|
annotations, sun.misc.SharedSecrets.getJavaLangAccess().
|
||||||
|
@ -58,12 +58,12 @@ import sun.reflect.annotation.AnnotationParser;
|
|||||||
public final
|
public final
|
||||||
class Field extends AccessibleObject implements Member {
|
class Field extends AccessibleObject implements Member {
|
||||||
|
|
||||||
private Class clazz;
|
private Class<?> clazz;
|
||||||
private int slot;
|
private int slot;
|
||||||
// This is guaranteed to be interned by the VM in the 1.4
|
// This is guaranteed to be interned by the VM in the 1.4
|
||||||
// reflection implementation
|
// reflection implementation
|
||||||
private String name;
|
private String name;
|
||||||
private Class type;
|
private Class<?> type;
|
||||||
private int modifiers;
|
private int modifiers;
|
||||||
// Generics and annotations support
|
// Generics and annotations support
|
||||||
private transient String signature;
|
private transient String signature;
|
||||||
@ -81,8 +81,8 @@ class Field extends AccessibleObject implements Member {
|
|||||||
|
|
||||||
// More complicated security check cache needed here than for
|
// More complicated security check cache needed here than for
|
||||||
// Class.newInstance() and Constructor.newInstance()
|
// Class.newInstance() and Constructor.newInstance()
|
||||||
private Class securityCheckCache;
|
private Class<?> securityCheckCache;
|
||||||
private Class securityCheckTargetClassCache;
|
private Class<?> securityCheckTargetClassCache;
|
||||||
|
|
||||||
// Generics infrastructure
|
// Generics infrastructure
|
||||||
|
|
||||||
@ -112,9 +112,9 @@ class Field extends AccessibleObject implements Member {
|
|||||||
* instantiation of these objects in Java code from the java.lang
|
* instantiation of these objects in Java code from the java.lang
|
||||||
* package via sun.reflect.LangReflectAccess.
|
* package via sun.reflect.LangReflectAccess.
|
||||||
*/
|
*/
|
||||||
Field(Class declaringClass,
|
Field(Class<?> declaringClass,
|
||||||
String name,
|
String name,
|
||||||
Class type,
|
Class<?> type,
|
||||||
int modifiers,
|
int modifiers,
|
||||||
int slot,
|
int slot,
|
||||||
String signature,
|
String signature,
|
||||||
@ -964,8 +964,8 @@ class Field extends AccessibleObject implements Member {
|
|||||||
private void doSecurityCheck(Object obj) throws IllegalAccessException {
|
private void doSecurityCheck(Object obj) throws IllegalAccessException {
|
||||||
if (!override) {
|
if (!override) {
|
||||||
if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
|
if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
|
||||||
Class caller = Reflection.getCallerClass(4);
|
Class<?> caller = Reflection.getCallerClass(4);
|
||||||
Class targetClass = ((obj == null || !Modifier.isProtected(modifiers))
|
Class<?> targetClass = ((obj == null || !Modifier.isProtected(modifiers))
|
||||||
? clazz
|
? clazz
|
||||||
: obj.getClass());
|
: obj.getClass());
|
||||||
|
|
||||||
@ -987,10 +987,10 @@ class Field extends AccessibleObject implements Member {
|
|||||||
/*
|
/*
|
||||||
* Utility routine to paper over array type names
|
* Utility routine to paper over array type names
|
||||||
*/
|
*/
|
||||||
static String getTypeName(Class type) {
|
static String getTypeName(Class<?> type) {
|
||||||
if (type.isArray()) {
|
if (type.isArray()) {
|
||||||
try {
|
try {
|
||||||
Class cl = type;
|
Class<?> cl = type;
|
||||||
int dimensions = 0;
|
int dimensions = 0;
|
||||||
while (cl.isArray()) {
|
while (cl.isArray()) {
|
||||||
dimensions++;
|
dimensions++;
|
||||||
@ -1025,9 +1025,9 @@ class Field extends AccessibleObject implements Member {
|
|||||||
return AnnotationParser.toArray(declaredAnnotations());
|
return AnnotationParser.toArray(declaredAnnotations());
|
||||||
}
|
}
|
||||||
|
|
||||||
private transient Map<Class, Annotation> declaredAnnotations;
|
private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
|
||||||
|
|
||||||
private synchronized Map<Class, Annotation> declaredAnnotations() {
|
private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
|
||||||
if (declaredAnnotations == null) {
|
if (declaredAnnotations == null) {
|
||||||
declaredAnnotations = AnnotationParser.parseAnnotations(
|
declaredAnnotations = AnnotationParser.parseAnnotations(
|
||||||
annotations, sun.misc.SharedSecrets.getJavaLangAccess().
|
annotations, sun.misc.SharedSecrets.getJavaLangAccess().
|
||||||
|
@ -61,14 +61,14 @@ import java.util.Map;
|
|||||||
public final
|
public final
|
||||||
class Method extends AccessibleObject implements GenericDeclaration,
|
class Method extends AccessibleObject implements GenericDeclaration,
|
||||||
Member {
|
Member {
|
||||||
private Class clazz;
|
private Class<?> clazz;
|
||||||
private int slot;
|
private int slot;
|
||||||
// This is guaranteed to be interned by the VM in the 1.4
|
// This is guaranteed to be interned by the VM in the 1.4
|
||||||
// reflection implementation
|
// reflection implementation
|
||||||
private String name;
|
private String name;
|
||||||
private Class returnType;
|
private Class<?> returnType;
|
||||||
private Class[] parameterTypes;
|
private Class<?>[] parameterTypes;
|
||||||
private Class[] exceptionTypes;
|
private Class<?>[] exceptionTypes;
|
||||||
private int modifiers;
|
private int modifiers;
|
||||||
// Generics and annotations support
|
// Generics and annotations support
|
||||||
private transient String signature;
|
private transient String signature;
|
||||||
@ -85,8 +85,8 @@ public final
|
|||||||
|
|
||||||
// More complicated security check cache needed here than for
|
// More complicated security check cache needed here than for
|
||||||
// Class.newInstance() and Constructor.newInstance()
|
// Class.newInstance() and Constructor.newInstance()
|
||||||
private Class securityCheckCache;
|
private Class<?> securityCheckCache;
|
||||||
private Class securityCheckTargetClassCache;
|
private Class<?> securityCheckTargetClassCache;
|
||||||
|
|
||||||
// Generics infrastructure
|
// Generics infrastructure
|
||||||
|
|
||||||
@ -114,11 +114,11 @@ public final
|
|||||||
* instantiation of these objects in Java code from the java.lang
|
* instantiation of these objects in Java code from the java.lang
|
||||||
* package via sun.reflect.LangReflectAccess.
|
* package via sun.reflect.LangReflectAccess.
|
||||||
*/
|
*/
|
||||||
Method(Class declaringClass,
|
Method(Class<?> declaringClass,
|
||||||
String name,
|
String name,
|
||||||
Class[] parameterTypes,
|
Class<?>[] parameterTypes,
|
||||||
Class returnType,
|
Class<?> returnType,
|
||||||
Class[] checkedExceptions,
|
Class<?>[] checkedExceptions,
|
||||||
int modifiers,
|
int modifiers,
|
||||||
int slot,
|
int slot,
|
||||||
String signature,
|
String signature,
|
||||||
@ -355,8 +355,8 @@ public final
|
|||||||
if (!returnType.equals(other.getReturnType()))
|
if (!returnType.equals(other.getReturnType()))
|
||||||
return false;
|
return false;
|
||||||
/* Avoid unnecessary cloning */
|
/* Avoid unnecessary cloning */
|
||||||
Class[] params1 = parameterTypes;
|
Class<?>[] params1 = parameterTypes;
|
||||||
Class[] params2 = other.parameterTypes;
|
Class<?>[] params2 = other.parameterTypes;
|
||||||
if (params1.length == params2.length) {
|
if (params1.length == params2.length) {
|
||||||
for (int i = 0; i < params1.length; i++) {
|
for (int i = 0; i < params1.length; i++) {
|
||||||
if (params1[i] != params2[i])
|
if (params1[i] != params2[i])
|
||||||
@ -410,14 +410,14 @@ public final
|
|||||||
sb.append(Field.getTypeName(getReturnType()) + " ");
|
sb.append(Field.getTypeName(getReturnType()) + " ");
|
||||||
sb.append(Field.getTypeName(getDeclaringClass()) + ".");
|
sb.append(Field.getTypeName(getDeclaringClass()) + ".");
|
||||||
sb.append(getName() + "(");
|
sb.append(getName() + "(");
|
||||||
Class[] params = parameterTypes; // avoid clone
|
Class<?>[] params = parameterTypes; // avoid clone
|
||||||
for (int j = 0; j < params.length; j++) {
|
for (int j = 0; j < params.length; j++) {
|
||||||
sb.append(Field.getTypeName(params[j]));
|
sb.append(Field.getTypeName(params[j]));
|
||||||
if (j < (params.length - 1))
|
if (j < (params.length - 1))
|
||||||
sb.append(",");
|
sb.append(",");
|
||||||
}
|
}
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
Class[] exceptions = exceptionTypes; // avoid clone
|
Class<?>[] exceptions = exceptionTypes; // avoid clone
|
||||||
if (exceptions.length > 0) {
|
if (exceptions.length > 0) {
|
||||||
sb.append(" throws ");
|
sb.append(" throws ");
|
||||||
for (int k = 0; k < exceptions.length; k++) {
|
for (int k = 0; k < exceptions.length; k++) {
|
||||||
@ -590,8 +590,8 @@ public final
|
|||||||
{
|
{
|
||||||
if (!override) {
|
if (!override) {
|
||||||
if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
|
if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
|
||||||
Class caller = Reflection.getCallerClass(1);
|
Class<?> caller = Reflection.getCallerClass(1);
|
||||||
Class targetClass = ((obj == null || !Modifier.isProtected(modifiers))
|
Class<?> targetClass = ((obj == null || !Modifier.isProtected(modifiers))
|
||||||
? clazz
|
? clazz
|
||||||
: obj.getClass());
|
: obj.getClass());
|
||||||
|
|
||||||
@ -702,9 +702,9 @@ public final
|
|||||||
return AnnotationParser.toArray(declaredAnnotations());
|
return AnnotationParser.toArray(declaredAnnotations());
|
||||||
}
|
}
|
||||||
|
|
||||||
private transient Map<Class, Annotation> declaredAnnotations;
|
private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
|
||||||
|
|
||||||
private synchronized Map<Class, Annotation> declaredAnnotations() {
|
private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
|
||||||
if (declaredAnnotations == null) {
|
if (declaredAnnotations == null) {
|
||||||
declaredAnnotations = AnnotationParser.parseAnnotations(
|
declaredAnnotations = AnnotationParser.parseAnnotations(
|
||||||
annotations, sun.misc.SharedSecrets.getJavaLangAccess().
|
annotations, sun.misc.SharedSecrets.getJavaLangAccess().
|
||||||
@ -731,7 +731,7 @@ public final
|
|||||||
public Object getDefaultValue() {
|
public Object getDefaultValue() {
|
||||||
if (annotationDefault == null)
|
if (annotationDefault == null)
|
||||||
return null;
|
return null;
|
||||||
Class memberType = AnnotationType.invocationHandlerReturnType(
|
Class<?> memberType = AnnotationType.invocationHandlerReturnType(
|
||||||
getReturnType());
|
getReturnType());
|
||||||
Object result = AnnotationParser.parseMemberValue(
|
Object result = AnnotationParser.parseMemberValue(
|
||||||
memberType, ByteBuffer.wrap(annotationDefault),
|
memberType, ByteBuffer.wrap(annotationDefault),
|
||||||
|
@ -350,7 +350,7 @@ public class Proxy implements java.io.Serializable {
|
|||||||
throw new IllegalArgumentException("interface limit exceeded");
|
throw new IllegalArgumentException("interface limit exceeded");
|
||||||
}
|
}
|
||||||
|
|
||||||
Class proxyClass = null;
|
Class<?> proxyClass = null;
|
||||||
|
|
||||||
/* collect interface names to use as key for proxy class cache */
|
/* collect interface names to use as key for proxy class cache */
|
||||||
String[] interfaceNames = new String[interfaces.length];
|
String[] interfaceNames = new String[interfaces.length];
|
||||||
@ -364,7 +364,7 @@ public class Proxy implements java.io.Serializable {
|
|||||||
* interface to the same Class object.
|
* interface to the same Class object.
|
||||||
*/
|
*/
|
||||||
String interfaceName = interfaces[i].getName();
|
String interfaceName = interfaces[i].getName();
|
||||||
Class interfaceClass = null;
|
Class<?> interfaceClass = null;
|
||||||
try {
|
try {
|
||||||
interfaceClass = Class.forName(interfaceName, false, loader);
|
interfaceClass = Class.forName(interfaceName, false, loader);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
@ -33,9 +33,9 @@ import sun.reflect.ConstructorAccessor;
|
|||||||
package to instantiate objects in this package. */
|
package to instantiate objects in this package. */
|
||||||
|
|
||||||
class ReflectAccess implements sun.reflect.LangReflectAccess {
|
class ReflectAccess implements sun.reflect.LangReflectAccess {
|
||||||
public Field newField(Class declaringClass,
|
public Field newField(Class<?> declaringClass,
|
||||||
String name,
|
String name,
|
||||||
Class type,
|
Class<?> type,
|
||||||
int modifiers,
|
int modifiers,
|
||||||
int slot,
|
int slot,
|
||||||
String signature,
|
String signature,
|
||||||
@ -50,11 +50,11 @@ class ReflectAccess implements sun.reflect.LangReflectAccess {
|
|||||||
annotations);
|
annotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Method newMethod(Class declaringClass,
|
public Method newMethod(Class<?> declaringClass,
|
||||||
String name,
|
String name,
|
||||||
Class[] parameterTypes,
|
Class<?>[] parameterTypes,
|
||||||
Class returnType,
|
Class<?> returnType,
|
||||||
Class[] checkedExceptions,
|
Class<?>[] checkedExceptions,
|
||||||
int modifiers,
|
int modifiers,
|
||||||
int slot,
|
int slot,
|
||||||
String signature,
|
String signature,
|
||||||
@ -76,8 +76,8 @@ class ReflectAccess implements sun.reflect.LangReflectAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T> Constructor<T> newConstructor(Class<T> declaringClass,
|
public <T> Constructor<T> newConstructor(Class<T> declaringClass,
|
||||||
Class[] parameterTypes,
|
Class<?>[] parameterTypes,
|
||||||
Class[] checkedExceptions,
|
Class<?>[] checkedExceptions,
|
||||||
int modifiers,
|
int modifiers,
|
||||||
int slot,
|
int slot,
|
||||||
String signature,
|
String signature,
|
||||||
@ -102,29 +102,29 @@ class ReflectAccess implements sun.reflect.LangReflectAccess {
|
|||||||
m.setMethodAccessor(accessor);
|
m.setMethodAccessor(accessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstructorAccessor getConstructorAccessor(Constructor c) {
|
public ConstructorAccessor getConstructorAccessor(Constructor<?> c) {
|
||||||
return c.getConstructorAccessor();
|
return c.getConstructorAccessor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConstructorAccessor(Constructor c,
|
public void setConstructorAccessor(Constructor<?> c,
|
||||||
ConstructorAccessor accessor)
|
ConstructorAccessor accessor)
|
||||||
{
|
{
|
||||||
c.setConstructorAccessor(accessor);
|
c.setConstructorAccessor(accessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getConstructorSlot(Constructor c) {
|
public int getConstructorSlot(Constructor<?> c) {
|
||||||
return c.getSlot();
|
return c.getSlot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getConstructorSignature(Constructor c) {
|
public String getConstructorSignature(Constructor<?> c) {
|
||||||
return c.getSignature();
|
return c.getSignature();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getConstructorAnnotations(Constructor c) {
|
public byte[] getConstructorAnnotations(Constructor<?> c) {
|
||||||
return c.getRawAnnotations();
|
return c.getRawAnnotations();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getConstructorParameterAnnotations(Constructor c) {
|
public byte[] getConstructorParameterAnnotations(Constructor<?> c) {
|
||||||
return c.getRawParameterAnnotations();
|
return c.getRawParameterAnnotations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ import java.lang.reflect.*;
|
|||||||
public interface LangReflectAccess {
|
public interface LangReflectAccess {
|
||||||
/** Creates a new java.lang.reflect.Field. Access checks as per
|
/** Creates a new java.lang.reflect.Field. Access checks as per
|
||||||
java.lang.reflect.AccessibleObject are not overridden. */
|
java.lang.reflect.AccessibleObject are not overridden. */
|
||||||
public Field newField(Class declaringClass,
|
public Field newField(Class<?> declaringClass,
|
||||||
String name,
|
String name,
|
||||||
Class type,
|
Class<?> type,
|
||||||
int modifiers,
|
int modifiers,
|
||||||
int slot,
|
int slot,
|
||||||
String signature,
|
String signature,
|
||||||
@ -43,11 +43,11 @@ public interface LangReflectAccess {
|
|||||||
|
|
||||||
/** Creates a new java.lang.reflect.Method. Access checks as per
|
/** Creates a new java.lang.reflect.Method. Access checks as per
|
||||||
java.lang.reflect.AccessibleObject are not overridden. */
|
java.lang.reflect.AccessibleObject are not overridden. */
|
||||||
public Method newMethod(Class declaringClass,
|
public Method newMethod(Class<?> declaringClass,
|
||||||
String name,
|
String name,
|
||||||
Class[] parameterTypes,
|
Class<?>[] parameterTypes,
|
||||||
Class returnType,
|
Class<?> returnType,
|
||||||
Class[] checkedExceptions,
|
Class<?>[] checkedExceptions,
|
||||||
int modifiers,
|
int modifiers,
|
||||||
int slot,
|
int slot,
|
||||||
String signature,
|
String signature,
|
||||||
@ -58,8 +58,8 @@ public interface LangReflectAccess {
|
|||||||
/** Creates a new java.lang.reflect.Constructor. Access checks as
|
/** Creates a new java.lang.reflect.Constructor. Access checks as
|
||||||
per java.lang.reflect.AccessibleObject are not overridden. */
|
per java.lang.reflect.AccessibleObject are not overridden. */
|
||||||
public <T> Constructor<T> newConstructor(Class<T> declaringClass,
|
public <T> Constructor<T> newConstructor(Class<T> declaringClass,
|
||||||
Class[] parameterTypes,
|
Class<?>[] parameterTypes,
|
||||||
Class[] checkedExceptions,
|
Class<?>[] checkedExceptions,
|
||||||
int modifiers,
|
int modifiers,
|
||||||
int slot,
|
int slot,
|
||||||
String signature,
|
String signature,
|
||||||
@ -74,24 +74,24 @@ public interface LangReflectAccess {
|
|||||||
|
|
||||||
/** Gets the ConstructorAccessor object for a
|
/** Gets the ConstructorAccessor object for a
|
||||||
java.lang.reflect.Constructor */
|
java.lang.reflect.Constructor */
|
||||||
public ConstructorAccessor getConstructorAccessor(Constructor c);
|
public ConstructorAccessor getConstructorAccessor(Constructor<?> c);
|
||||||
|
|
||||||
/** Sets the ConstructorAccessor object for a
|
/** Sets the ConstructorAccessor object for a
|
||||||
java.lang.reflect.Constructor */
|
java.lang.reflect.Constructor */
|
||||||
public void setConstructorAccessor(Constructor c,
|
public void setConstructorAccessor(Constructor<?> c,
|
||||||
ConstructorAccessor accessor);
|
ConstructorAccessor accessor);
|
||||||
|
|
||||||
/** Gets the "slot" field from a Constructor (used for serialization) */
|
/** Gets the "slot" field from a Constructor (used for serialization) */
|
||||||
public int getConstructorSlot(Constructor c);
|
public int getConstructorSlot(Constructor<?> c);
|
||||||
|
|
||||||
/** Gets the "signature" field from a Constructor (used for serialization) */
|
/** Gets the "signature" field from a Constructor (used for serialization) */
|
||||||
public String getConstructorSignature(Constructor c);
|
public String getConstructorSignature(Constructor<?> c);
|
||||||
|
|
||||||
/** Gets the "annotations" field from a Constructor (used for serialization) */
|
/** Gets the "annotations" field from a Constructor (used for serialization) */
|
||||||
public byte[] getConstructorAnnotations(Constructor c);
|
public byte[] getConstructorAnnotations(Constructor<?> c);
|
||||||
|
|
||||||
/** Gets the "parameterAnnotations" field from a Constructor (used for serialization) */
|
/** Gets the "parameterAnnotations" field from a Constructor (used for serialization) */
|
||||||
public byte[] getConstructorParameterAnnotations(Constructor c);
|
public byte[] getConstructorParameterAnnotations(Constructor<?> c);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Copying routines, needed to quickly fabricate new Field,
|
// Copying routines, needed to quickly fabricate new Field,
|
||||||
|
@ -40,17 +40,17 @@ import java.security.PrivilegedAction;
|
|||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
class AnnotationInvocationHandler implements InvocationHandler, Serializable {
|
class AnnotationInvocationHandler implements InvocationHandler, Serializable {
|
||||||
private final Class type;
|
private final Class<? extends Annotation> type;
|
||||||
private final Map<String, Object> memberValues;
|
private final Map<String, Object> memberValues;
|
||||||
|
|
||||||
AnnotationInvocationHandler(Class type, Map<String, Object> memberValues) {
|
AnnotationInvocationHandler(Class<? extends Annotation> type, Map<String, Object> memberValues) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.memberValues = memberValues;
|
this.memberValues = memberValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) {
|
public Object invoke(Object proxy, Method method, Object[] args) {
|
||||||
String member = method.getName();
|
String member = method.getName();
|
||||||
Class[] paramTypes = method.getParameterTypes();
|
Class<?>[] paramTypes = method.getParameterTypes();
|
||||||
|
|
||||||
// Handle Object and Annotation methods
|
// Handle Object and Annotation methods
|
||||||
if (member.equals("equals") && paramTypes.length == 1 &&
|
if (member.equals("equals") && paramTypes.length == 1 &&
|
||||||
@ -84,7 +84,7 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
|
|||||||
* if Cloneable had a public clone method.
|
* if Cloneable had a public clone method.
|
||||||
*/
|
*/
|
||||||
private Object cloneArray(Object array) {
|
private Object cloneArray(Object array) {
|
||||||
Class type = array.getClass();
|
Class<?> type = array.getClass();
|
||||||
|
|
||||||
if (type == byte[].class) {
|
if (type == byte[].class) {
|
||||||
byte[] byteArray = (byte[])array;
|
byte[] byteArray = (byte[])array;
|
||||||
@ -151,7 +151,7 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
|
|||||||
* Translates a member value (in "dynamic proxy return form") into a string
|
* Translates a member value (in "dynamic proxy return form") into a string
|
||||||
*/
|
*/
|
||||||
private static String memberValueToString(Object value) {
|
private static String memberValueToString(Object value) {
|
||||||
Class type = value.getClass();
|
Class<?> type = value.getClass();
|
||||||
if (!type.isArray()) // primitive, string, class, enum const,
|
if (!type.isArray()) // primitive, string, class, enum const,
|
||||||
// or annotation
|
// or annotation
|
||||||
return value.toString();
|
return value.toString();
|
||||||
@ -229,7 +229,7 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
|
|||||||
* two members are identical object references.
|
* two members are identical object references.
|
||||||
*/
|
*/
|
||||||
private static boolean memberValueEquals(Object v1, Object v2) {
|
private static boolean memberValueEquals(Object v1, Object v2) {
|
||||||
Class type = v1.getClass();
|
Class<?> type = v1.getClass();
|
||||||
|
|
||||||
// Check for primitive, string, class, enum const, annotation,
|
// Check for primitive, string, class, enum const, annotation,
|
||||||
// or ExceptionProxy
|
// or ExceptionProxy
|
||||||
@ -301,7 +301,7 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
|
|||||||
* Computes hashCode of a member value (in "dynamic proxy return form")
|
* Computes hashCode of a member value (in "dynamic proxy return form")
|
||||||
*/
|
*/
|
||||||
private static int memberValueHashCode(Object value) {
|
private static int memberValueHashCode(Object value) {
|
||||||
Class type = value.getClass();
|
Class<?> type = value.getClass();
|
||||||
if (!type.isArray()) // primitive, string, class, enum const,
|
if (!type.isArray()) // primitive, string, class, enum const,
|
||||||
// or annotation
|
// or annotation
|
||||||
return value.hashCode();
|
return value.hashCode();
|
||||||
@ -340,11 +340,11 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Class> memberTypes = annotationType.memberTypes();
|
Map<String, Class<?>> memberTypes = annotationType.memberTypes();
|
||||||
|
|
||||||
for (Map.Entry<String, Object> memberValue : memberValues.entrySet()) {
|
for (Map.Entry<String, Object> memberValue : memberValues.entrySet()) {
|
||||||
String name = memberValue.getKey();
|
String name = memberValue.getKey();
|
||||||
Class memberType = memberTypes.get(name);
|
Class<?> memberType = memberTypes.get(name);
|
||||||
if (memberType != null) { // i.e. member still exists
|
if (memberType != null) { // i.e. member still exists
|
||||||
Object value = memberValue.getValue();
|
Object value = memberValue.getValue();
|
||||||
if (!(memberType.isInstance(value) ||
|
if (!(memberType.isInstance(value) ||
|
||||||
|
@ -59,10 +59,10 @@ public class AnnotationParser {
|
|||||||
* @throws AnnotationFormatError if an annotation is found to be
|
* @throws AnnotationFormatError if an annotation is found to be
|
||||||
* malformed.
|
* malformed.
|
||||||
*/
|
*/
|
||||||
public static Map<Class, Annotation> parseAnnotations(
|
public static Map<Class<? extends Annotation>, Annotation> parseAnnotations(
|
||||||
byte[] rawAnnotations,
|
byte[] rawAnnotations,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
if (rawAnnotations == null)
|
if (rawAnnotations == null)
|
||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
|
|
||||||
@ -76,17 +76,18 @@ public class AnnotationParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<Class, Annotation> parseAnnotations2(
|
private static Map<Class<? extends Annotation>, Annotation> parseAnnotations2(
|
||||||
byte[] rawAnnotations,
|
byte[] rawAnnotations,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
Map<Class, Annotation> result = new LinkedHashMap<Class, Annotation>();
|
Map<Class<? extends Annotation>, Annotation> result =
|
||||||
|
new LinkedHashMap<Class<? extends Annotation>, Annotation>();
|
||||||
ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
|
ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
|
||||||
int numAnnotations = buf.getShort() & 0xFFFF;
|
int numAnnotations = buf.getShort() & 0xFFFF;
|
||||||
for (int i = 0; i < numAnnotations; i++) {
|
for (int i = 0; i < numAnnotations; i++) {
|
||||||
Annotation a = parseAnnotation(buf, constPool, container, false);
|
Annotation a = parseAnnotation(buf, constPool, container, false);
|
||||||
if (a != null) {
|
if (a != null) {
|
||||||
Class klass = a.annotationType();
|
Class<? extends Annotation> klass = a.annotationType();
|
||||||
AnnotationType type = AnnotationType.getInstance(klass);
|
AnnotationType type = AnnotationType.getInstance(klass);
|
||||||
if (type.retention() == RetentionPolicy.RUNTIME)
|
if (type.retention() == RetentionPolicy.RUNTIME)
|
||||||
if (result.put(klass, a) != null)
|
if (result.put(klass, a) != null)
|
||||||
@ -123,7 +124,7 @@ public class AnnotationParser {
|
|||||||
public static Annotation[][] parseParameterAnnotations(
|
public static Annotation[][] parseParameterAnnotations(
|
||||||
byte[] rawAnnotations,
|
byte[] rawAnnotations,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
try {
|
try {
|
||||||
return parseParameterAnnotations2(rawAnnotations, constPool, container);
|
return parseParameterAnnotations2(rawAnnotations, constPool, container);
|
||||||
} catch(BufferUnderflowException e) {
|
} catch(BufferUnderflowException e) {
|
||||||
@ -138,7 +139,7 @@ public class AnnotationParser {
|
|||||||
private static Annotation[][] parseParameterAnnotations2(
|
private static Annotation[][] parseParameterAnnotations2(
|
||||||
byte[] rawAnnotations,
|
byte[] rawAnnotations,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
|
ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
|
||||||
int numParameters = buf.get() & 0xFF;
|
int numParameters = buf.get() & 0xFF;
|
||||||
Annotation[][] result = new Annotation[numParameters][];
|
Annotation[][] result = new Annotation[numParameters][];
|
||||||
@ -188,15 +189,15 @@ public class AnnotationParser {
|
|||||||
*/
|
*/
|
||||||
private static Annotation parseAnnotation(ByteBuffer buf,
|
private static Annotation parseAnnotation(ByteBuffer buf,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container,
|
Class<?> container,
|
||||||
boolean exceptionOnMissingAnnotationClass) {
|
boolean exceptionOnMissingAnnotationClass) {
|
||||||
int typeIndex = buf.getShort() & 0xFFFF;
|
int typeIndex = buf.getShort() & 0xFFFF;
|
||||||
Class annotationClass = null;
|
Class<? extends Annotation> annotationClass = null;
|
||||||
String sig = "[unknown]";
|
String sig = "[unknown]";
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
sig = constPool.getUTF8At(typeIndex);
|
sig = constPool.getUTF8At(typeIndex);
|
||||||
annotationClass = parseSig(sig, container);
|
annotationClass = (Class<? extends Annotation>)parseSig(sig, container);
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
// support obsolete early jsr175 format class files
|
// support obsolete early jsr175 format class files
|
||||||
annotationClass = constPool.getClassAt(typeIndex);
|
annotationClass = constPool.getClassAt(typeIndex);
|
||||||
@ -223,7 +224,7 @@ public class AnnotationParser {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Class> memberTypes = type.memberTypes();
|
Map<String, Class<?>> memberTypes = type.memberTypes();
|
||||||
Map<String, Object> memberValues =
|
Map<String, Object> memberValues =
|
||||||
new LinkedHashMap<String, Object>(type.memberDefaults());
|
new LinkedHashMap<String, Object>(type.memberDefaults());
|
||||||
|
|
||||||
@ -231,7 +232,7 @@ public class AnnotationParser {
|
|||||||
for (int i = 0; i < numMembers; i++) {
|
for (int i = 0; i < numMembers; i++) {
|
||||||
int memberNameIndex = buf.getShort() & 0xFFFF;
|
int memberNameIndex = buf.getShort() & 0xFFFF;
|
||||||
String memberName = constPool.getUTF8At(memberNameIndex);
|
String memberName = constPool.getUTF8At(memberNameIndex);
|
||||||
Class memberType = memberTypes.get(memberName);
|
Class<?> memberType = memberTypes.get(memberName);
|
||||||
|
|
||||||
if (memberType == null) {
|
if (memberType == null) {
|
||||||
// Member is no longer present in annotation type; ignore it
|
// Member is no longer present in annotation type; ignore it
|
||||||
@ -252,7 +253,7 @@ public class AnnotationParser {
|
|||||||
* member -> value map.
|
* member -> value map.
|
||||||
*/
|
*/
|
||||||
public static Annotation annotationForMap(
|
public static Annotation annotationForMap(
|
||||||
Class type, Map<String, Object> memberValues)
|
Class<? extends Annotation> type, Map<String, Object> memberValues)
|
||||||
{
|
{
|
||||||
return (Annotation) Proxy.newProxyInstance(
|
return (Annotation) Proxy.newProxyInstance(
|
||||||
type.getClassLoader(), new Class[] { type },
|
type.getClassLoader(), new Class[] { type },
|
||||||
@ -286,14 +287,15 @@ public class AnnotationParser {
|
|||||||
* The member must be of the indicated type. If it is not, this
|
* The member must be of the indicated type. If it is not, this
|
||||||
* method returns an AnnotationTypeMismatchExceptionProxy.
|
* method returns an AnnotationTypeMismatchExceptionProxy.
|
||||||
*/
|
*/
|
||||||
public static Object parseMemberValue(Class memberType, ByteBuffer buf,
|
public static Object parseMemberValue(Class<?> memberType,
|
||||||
|
ByteBuffer buf,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
Object result = null;
|
Object result = null;
|
||||||
int tag = buf.get();
|
int tag = buf.get();
|
||||||
switch(tag) {
|
switch(tag) {
|
||||||
case 'e':
|
case 'e':
|
||||||
return parseEnumValue(memberType, buf, constPool, container);
|
return parseEnumValue((Class<? extends Enum<?>>)memberType, buf, constPool, container);
|
||||||
case 'c':
|
case 'c':
|
||||||
result = parseClassValue(buf, constPool, container);
|
result = parseClassValue(buf, constPool, container);
|
||||||
break;
|
break;
|
||||||
@ -361,7 +363,7 @@ public class AnnotationParser {
|
|||||||
*/
|
*/
|
||||||
private static Object parseClassValue(ByteBuffer buf,
|
private static Object parseClassValue(ByteBuffer buf,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
int classIndex = buf.getShort() & 0xFFFF;
|
int classIndex = buf.getShort() & 0xFFFF;
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
@ -379,7 +381,7 @@ public class AnnotationParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> parseSig(String sig, Class container) {
|
private static Class<?> parseSig(String sig, Class<?> container) {
|
||||||
if (sig.equals("V")) return void.class;
|
if (sig.equals("V")) return void.class;
|
||||||
SignatureParser parser = SignatureParser.make();
|
SignatureParser parser = SignatureParser.make();
|
||||||
TypeSignature typeSig = parser.parseTypeSig(sig);
|
TypeSignature typeSig = parser.parseTypeSig(sig);
|
||||||
@ -389,7 +391,7 @@ public class AnnotationParser {
|
|||||||
Type result = reify.getResult();
|
Type result = reify.getResult();
|
||||||
return toClass(result);
|
return toClass(result);
|
||||||
}
|
}
|
||||||
static Class toClass(Type o) {
|
static Class<?> toClass(Type o) {
|
||||||
if (o instanceof GenericArrayType)
|
if (o instanceof GenericArrayType)
|
||||||
return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
|
return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
|
||||||
0)
|
0)
|
||||||
@ -409,9 +411,9 @@ public class AnnotationParser {
|
|||||||
* u2 const_name_index;
|
* u2 const_name_index;
|
||||||
* } enum_const_value;
|
* } enum_const_value;
|
||||||
*/
|
*/
|
||||||
private static Object parseEnumValue(Class enumType, ByteBuffer buf,
|
private static Object parseEnumValue(Class<? extends Enum> enumType, ByteBuffer buf,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
int typeNameIndex = buf.getShort() & 0xFFFF;
|
int typeNameIndex = buf.getShort() & 0xFFFF;
|
||||||
String typeName = constPool.getUTF8At(typeNameIndex);
|
String typeName = constPool.getUTF8At(typeNameIndex);
|
||||||
int constNameIndex = buf.getShort() & 0xFFFF;
|
int constNameIndex = buf.getShort() & 0xFFFF;
|
||||||
@ -449,12 +451,12 @@ public class AnnotationParser {
|
|||||||
* If the array values do not match arrayType, an
|
* If the array values do not match arrayType, an
|
||||||
* AnnotationTypeMismatchExceptionProxy will be returned.
|
* AnnotationTypeMismatchExceptionProxy will be returned.
|
||||||
*/
|
*/
|
||||||
private static Object parseArray(Class arrayType,
|
private static Object parseArray(Class<?> arrayType,
|
||||||
ByteBuffer buf,
|
ByteBuffer buf,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
int length = buf.getShort() & 0xFFFF; // Number of array components
|
int length = buf.getShort() & 0xFFFF; // Number of array components
|
||||||
Class componentType = arrayType.getComponentType();
|
Class<?> componentType = arrayType.getComponentType();
|
||||||
|
|
||||||
if (componentType == byte.class) {
|
if (componentType == byte.class) {
|
||||||
return parseByteArray(length, buf, constPool);
|
return parseByteArray(length, buf, constPool);
|
||||||
@ -477,11 +479,11 @@ public class AnnotationParser {
|
|||||||
} else if (componentType == Class.class) {
|
} else if (componentType == Class.class) {
|
||||||
return parseClassArray(length, buf, constPool, container);
|
return parseClassArray(length, buf, constPool, container);
|
||||||
} else if (componentType.isEnum()) {
|
} else if (componentType.isEnum()) {
|
||||||
return parseEnumArray(length, componentType, buf,
|
return parseEnumArray(length, (Class<? extends Enum>)componentType, buf,
|
||||||
constPool, container);
|
constPool, container);
|
||||||
} else {
|
} else {
|
||||||
assert componentType.isAnnotation();
|
assert componentType.isAnnotation();
|
||||||
return parseAnnotationArray(length, componentType, buf,
|
return parseAnnotationArray(length, (Class <? extends Annotation>)componentType, buf,
|
||||||
constPool, container);
|
constPool, container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -660,8 +662,8 @@ public class AnnotationParser {
|
|||||||
private static Object parseClassArray(int length,
|
private static Object parseClassArray(int length,
|
||||||
ByteBuffer buf,
|
ByteBuffer buf,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
Object[] result = new Class[length];
|
Object[] result = new Class<?>[length];
|
||||||
boolean typeMismatch = false;
|
boolean typeMismatch = false;
|
||||||
int tag = 0;
|
int tag = 0;
|
||||||
|
|
||||||
@ -677,10 +679,10 @@ public class AnnotationParser {
|
|||||||
return typeMismatch ? exceptionProxy(tag) : result;
|
return typeMismatch ? exceptionProxy(tag) : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object parseEnumArray(int length, Class enumType,
|
private static Object parseEnumArray(int length, Class<? extends Enum> enumType,
|
||||||
ByteBuffer buf,
|
ByteBuffer buf,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
Object[] result = (Object[]) Array.newInstance(enumType, length);
|
Object[] result = (Object[]) Array.newInstance(enumType, length);
|
||||||
boolean typeMismatch = false;
|
boolean typeMismatch = false;
|
||||||
int tag = 0;
|
int tag = 0;
|
||||||
@ -698,10 +700,10 @@ public class AnnotationParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Object parseAnnotationArray(int length,
|
private static Object parseAnnotationArray(int length,
|
||||||
Class annotationType,
|
Class<? extends Annotation> annotationType,
|
||||||
ByteBuffer buf,
|
ByteBuffer buf,
|
||||||
ConstantPool constPool,
|
ConstantPool constPool,
|
||||||
Class container) {
|
Class<?> container) {
|
||||||
Object[] result = (Object[]) Array.newInstance(annotationType, length);
|
Object[] result = (Object[]) Array.newInstance(annotationType, length);
|
||||||
boolean typeMismatch = false;
|
boolean typeMismatch = false;
|
||||||
int tag = 0;
|
int tag = 0;
|
||||||
@ -797,7 +799,7 @@ public class AnnotationParser {
|
|||||||
* it is needed.
|
* it is needed.
|
||||||
*/
|
*/
|
||||||
private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
|
private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
|
||||||
public static Annotation[] toArray(Map<Class, Annotation> annotations) {
|
public static Annotation[] toArray(Map<Class<? extends Annotation>, Annotation> annotations) {
|
||||||
return annotations.values().toArray(EMPTY_ANNOTATION_ARRAY);
|
return annotations.values().toArray(EMPTY_ANNOTATION_ARRAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class AnnotationType {
|
|||||||
* types. This matches the return value that must be used for a
|
* types. This matches the return value that must be used for a
|
||||||
* dynamic proxy, allowing for a simple isInstance test.
|
* dynamic proxy, allowing for a simple isInstance test.
|
||||||
*/
|
*/
|
||||||
private final Map<String, Class> memberTypes = new HashMap<String,Class>();
|
private final Map<String, Class<?>> memberTypes = new HashMap<String,Class<?>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Member name -> default value mapping.
|
* Member name -> default value mapping.
|
||||||
@ -76,12 +76,12 @@ public class AnnotationType {
|
|||||||
* does not represent a valid annotation type
|
* does not represent a valid annotation type
|
||||||
*/
|
*/
|
||||||
public static synchronized AnnotationType getInstance(
|
public static synchronized AnnotationType getInstance(
|
||||||
Class annotationClass)
|
Class<? extends Annotation> annotationClass)
|
||||||
{
|
{
|
||||||
AnnotationType result = sun.misc.SharedSecrets.getJavaLangAccess().
|
AnnotationType result = sun.misc.SharedSecrets.getJavaLangAccess().
|
||||||
getAnnotationType(annotationClass);
|
getAnnotationType(annotationClass);
|
||||||
if (result == null)
|
if (result == null)
|
||||||
result = new AnnotationType((Class<?>) annotationClass);
|
result = new AnnotationType((Class<? extends Annotation>) annotationClass);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ public class AnnotationType {
|
|||||||
* @throw IllegalArgumentException if the specified class object for
|
* @throw IllegalArgumentException if the specified class object for
|
||||||
* does not represent a valid annotation type
|
* does not represent a valid annotation type
|
||||||
*/
|
*/
|
||||||
private AnnotationType(final Class<?> annotationClass) {
|
private AnnotationType(final Class<? extends Annotation> annotationClass) {
|
||||||
if (!annotationClass.isAnnotation())
|
if (!annotationClass.isAnnotation())
|
||||||
throw new IllegalArgumentException("Not an annotation type");
|
throw new IllegalArgumentException("Not an annotation type");
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ public class AnnotationType {
|
|||||||
if (method.getParameterTypes().length != 0)
|
if (method.getParameterTypes().length != 0)
|
||||||
throw new IllegalArgumentException(method + " has params");
|
throw new IllegalArgumentException(method + " has params");
|
||||||
String name = method.getName();
|
String name = method.getName();
|
||||||
Class type = method.getReturnType();
|
Class<?> type = method.getReturnType();
|
||||||
memberTypes.put(name, invocationHandlerReturnType(type));
|
memberTypes.put(name, invocationHandlerReturnType(type));
|
||||||
members.put(name, method);
|
members.put(name, method);
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ public class AnnotationType {
|
|||||||
* the specified type (which is assumed to be a legal member type
|
* the specified type (which is assumed to be a legal member type
|
||||||
* for an annotation).
|
* for an annotation).
|
||||||
*/
|
*/
|
||||||
public static Class invocationHandlerReturnType(Class type) {
|
public static Class<?> invocationHandlerReturnType(Class<?> type) {
|
||||||
// Translate primitives to wrappers
|
// Translate primitives to wrappers
|
||||||
if (type == byte.class)
|
if (type == byte.class)
|
||||||
return Byte.class;
|
return Byte.class;
|
||||||
@ -167,7 +167,7 @@ public class AnnotationType {
|
|||||||
* Returns member types for this annotation type
|
* Returns member types for this annotation type
|
||||||
* (member name -> type mapping).
|
* (member name -> type mapping).
|
||||||
*/
|
*/
|
||||||
public Map<String, Class> memberTypes() {
|
public Map<String, Class<?>> memberTypes() {
|
||||||
return memberTypes;
|
return memberTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user