src/share/classes/java/lang/Class.java

Print this page

        

*** 263,273 **** } return forName0(name, initialize, loader); } /** Called after security checks have been made. */ ! private static native Class forName0(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException; /** * Creates a new instance of the class represented by this {@code Class} --- 263,273 ---- } return forName0(name, initialize, loader); } /** Called after security checks have been made. */ ! private static native Class<?> forName0(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException; /** * Creates a new instance of the class represented by this {@code Class}
*** 337,347 **** throw new IllegalAccessException( "Can not call newInstance() on the Class for java.lang.Class" ); } try { ! Class[] empty = {}; final Constructor<T> c = getConstructor0(empty, Member.DECLARED); // Disable accessibility checks on the constructor // since we have to do the security check here anyway // (the stack depth is wrong for the Constructor's // security check to work) --- 337,347 ---- throw new IllegalAccessException( "Can not call newInstance() on the Class for java.lang.Class" ); } try { ! Class<?>[] empty = {}; final Constructor<T> c = getConstructor0(empty, Member.DECLARED); // Disable accessibility checks on the constructor // since we have to do the security check here anyway // (the stack depth is wrong for the Constructor's // security check to work)
*** 359,369 **** } Constructor<T> tmpConstructor = cachedConstructor; // Security check (same as in java.lang.reflect.Constructor) int modifiers = tmpConstructor.getModifiers(); if (!Reflection.quickCheckMemberAccess(this, modifiers)) { ! Class caller = Reflection.getCallerClass(3); if (newInstanceCallerCache != caller) { Reflection.ensureMemberAccess(caller, this, null, modifiers); newInstanceCallerCache = caller; } } --- 359,369 ---- } Constructor<T> tmpConstructor = cachedConstructor; // Security check (same as in java.lang.reflect.Constructor) int modifiers = tmpConstructor.getModifiers(); if (!Reflection.quickCheckMemberAccess(this, modifiers)) { ! Class<?> caller = Reflection.getCallerClass(3); if (newInstanceCallerCache != caller) { Reflection.ensureMemberAccess(caller, this, null, modifiers); newInstanceCallerCache = caller; } }
*** 375,385 **** // Not reached return null; } } private volatile transient Constructor<T> cachedConstructor; ! private volatile transient Class newInstanceCallerCache; /** * Determines if the specified {@code Object} is assignment-compatible * with the object represented by this {@code Class}. This method is --- 375,385 ---- // Not reached return null; } } private volatile transient Constructor<T> cachedConstructor; ! private volatile transient Class<?> newInstanceCallerCache; /** * Determines if the specified {@code Object} is assignment-compatible * with the object represented by this {@code Class}. This method is
*** 636,646 **** */ public TypeVariable<Class<T>>[] getTypeParameters() { if (getGenericSignature() != null) return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters(); else ! return (TypeVariable<Class<T>>[])new TypeVariable[0]; } /** * Returns the {@code Class} representing the superclass of the entity --- 636,646 ---- */ public TypeVariable<Class<T>>[] getTypeParameters() { if (getGenericSignature() != null) return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters(); else ! return (TypeVariable<Class<T>>[])new TypeVariable<?>[0]; } /** * Returns the {@code Class} representing the superclass of the entity
*** 899,909 **** if (!enclosingInfo.isMethod()) return null; MethodRepository typeInfo = MethodRepository.make(enclosingInfo.getDescriptor(), getFactory()); ! Class returnType = toClass(typeInfo.getReturnType()); Type [] parameterTypes = typeInfo.getParameterTypes(); Class<?>[] parameterClasses = new Class<?>[parameterTypes.length]; // Convert Types to Classes; returned types *should* // be class objects since the methodDescriptor's used --- 899,909 ---- if (!enclosingInfo.isMethod()) return null; MethodRepository typeInfo = MethodRepository.make(enclosingInfo.getDescriptor(), getFactory()); ! Class<?> returnType = toClass(typeInfo.getReturnType()); Type [] parameterTypes = typeInfo.getParameterTypes(); Class<?>[] parameterClasses = new Class<?>[parameterTypes.length]; // Convert Types to Classes; returned types *should* // be class objects since the methodDescriptor's used
*** 994,1009 **** String getDescriptor() { return descriptor; } } ! private static Class toClass(Type o) { if (o instanceof GenericArrayType) return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()), 0) .getClass(); ! return (Class)o; } /** * If this {@code Class} object represents a local or anonymous * class within a constructor, returns a {@link --- 994,1009 ---- String getDescriptor() { return descriptor; } } ! private static Class<?> toClass(Type o) { if (o instanceof GenericArrayType) return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()), 0) .getClass(); ! return (Class<?>)o; } /** * If this {@code Class} object represents a local or anonymous * class within a constructor, returns a {@link
*** 1040,1050 **** /* * Loop over all declared constructors; match number * of and type of parameters. */ ! for(Constructor c: enclosingInfo.getEnclosingClass().getDeclaredConstructors()) { Class<?>[] candidateParamClasses = c.getParameterTypes(); if (candidateParamClasses.length == parameterClasses.length) { boolean matches = true; for(int i = 0; i < candidateParamClasses.length; i++) { if (!candidateParamClasses[i].equals(parameterClasses[i])) { --- 1040,1050 ---- /* * Loop over all declared constructors; match number * of and type of parameters. */ ! for(Constructor<?> c: enclosingInfo.getEnclosingClass().getDeclaredConstructors()) { Class<?>[] candidateParamClasses = c.getParameterTypes(); if (candidateParamClasses.length == parameterClasses.length) { boolean matches = true; for(int i = 0; i < candidateParamClasses.length; i++) { if (!candidateParamClasses[i].equals(parameterClasses[i])) {
*** 1302,1317 **** // is allowed to look at DECLARED classes because (1) it does not hand // out anything other than public members and (2) public member access // has already been ok'd by the SecurityManager. return java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Class[]>() { public Class[] run() { ! List<Class> list = new ArrayList<Class>(); ! Class currentClass = Class.this; while (currentClass != null) { ! Class[] members = currentClass.getDeclaredClasses(); for (int i = 0; i < members.length; i++) { if (Modifier.isPublic(members[i].getModifiers())) { list.add(members[i]); } } --- 1302,1317 ---- // is allowed to look at DECLARED classes because (1) it does not hand // out anything other than public members and (2) public member access // has already been ok'd by the SecurityManager. return java.security.AccessController.doPrivileged( ! new java.security.PrivilegedAction<Class<?>[]>() { public Class[] run() { ! List<Class<?>> list = new ArrayList<Class<?>>(); ! Class<?> currentClass = Class.this; while (currentClass != null) { ! Class<?>[] members = currentClass.getDeclaredClasses(); for (int i = 0; i < members.length; i++) { if (Modifier.isPublic(members[i].getModifiers())) { list.add(members[i]); } }
*** 2189,2199 **** private String resolveName(String name) { if (name == null) { return name; } if (!name.startsWith("/")) { ! Class c = this; while (c.isArray()) { c = c.getComponentType(); } String baseName = c.getName(); int index = baseName.lastIndexOf('.'); --- 2189,2199 ---- private String resolveName(String name) { if (name == null) { return name; } if (!name.startsWith("/")) { ! Class<?> c = this; while (c.isArray()) { c = c.getComponentType(); } String baseName = c.getName(); int index = baseName.lastIndexOf('.');
*** 2563,2578 **** // Now recur over superclass and direct superinterfaces. // Go over superinterfaces first so we can more easily filter // out concrete implementations inherited from superclasses at // the end. MethodArray inheritedMethods = new MethodArray(); ! Class[] interfaces = getInterfaces(); for (int i = 0; i < interfaces.length; i++) { inheritedMethods.addAll(interfaces[i].privateGetPublicMethods()); } if (!isInterface()) { ! Class c = getSuperclass(); if (c != null) { MethodArray supers = new MethodArray(); supers.addAll(c.privateGetPublicMethods()); // Filter out concrete implementations of any // interface methods --- 2563,2578 ---- // Now recur over superclass and direct superinterfaces. // Go over superinterfaces first so we can more easily filter // out concrete implementations inherited from superclasses at // the end. MethodArray inheritedMethods = new MethodArray(); ! Class<?>[] interfaces = getInterfaces(); for (int i = 0; i < interfaces.length; i++) { inheritedMethods.addAll(interfaces[i].privateGetPublicMethods()); } if (!isInterface()) { ! Class<?> c = getSuperclass(); if (c != null) { MethodArray supers = new MethodArray(); supers.addAll(c.privateGetPublicMethods()); // Filter out concrete implementations of any // interface methods
*** 2630,2649 **** // Search declared public fields if ((res = searchFields(privateGetDeclaredFields(true), name)) != null) { return res; } // Direct superinterfaces, recursively ! Class[] interfaces = getInterfaces(); for (int i = 0; i < interfaces.length; i++) { ! Class c = interfaces[i]; if ((res = c.getField0(name)) != null) { return res; } } // Direct superclass, recursively if (!isInterface()) { ! Class c = getSuperclass(); if (c != null) { if ((res = c.getField0(name)) != null) { return res; } } --- 2630,2649 ---- // Search declared public fields if ((res = searchFields(privateGetDeclaredFields(true), name)) != null) { return res; } // Direct superinterfaces, recursively ! Class<?>[] interfaces = getInterfaces(); for (int i = 0; i < interfaces.length; i++) { ! Class<?> c = interfaces[i]; if ((res = c.getField0(name)) != null) { return res; } } // Direct superclass, recursively if (!isInterface()) { ! Class<?> c = getSuperclass(); if (c != null) { if ((res = c.getField0(name)) != null) { return res; } }
*** 2651,2661 **** return null; } private static Method searchMethods(Method[] methods, String name, ! Class[] parameterTypes) { Method res = null; String internedName = name.intern(); for (int i = 0; i < methods.length; i++) { Method m = methods[i]; --- 2651,2661 ---- return null; } private static Method searchMethods(Method[] methods, String name, ! Class<?>[] parameterTypes) { Method res = null; String internedName = name.intern(); for (int i = 0; i < methods.length; i++) { Method m = methods[i];
*** 2668,2678 **** return (res == null ? res : getReflectionFactory().copyMethod(res)); } ! private Method getMethod0(String name, Class[] parameterTypes) { // Note: the intent is that the search algorithm this routine // uses be equivalent to the ordering imposed by // privateGetPublicMethods(). It fetches only the declared // public methods for each class, however, to reduce the // number of Method objects which have to be created for the --- 2668,2678 ---- return (res == null ? res : getReflectionFactory().copyMethod(res)); } ! private Method getMethod0(String name, Class<?>[] parameterTypes) { // Note: the intent is that the search algorithm this routine // uses be equivalent to the ordering imposed by // privateGetPublicMethods(). It fetches only the declared // public methods for each class, however, to reduce the // number of Method objects which have to be created for the
*** 2685,2714 **** parameterTypes)) != null) { return res; } // Search superclass's methods if (!isInterface()) { ! Class c = getSuperclass(); if (c != null) { if ((res = c.getMethod0(name, parameterTypes)) != null) { return res; } } } // Search superinterfaces' methods ! Class[] interfaces = getInterfaces(); for (int i = 0; i < interfaces.length; i++) { ! Class c = interfaces[i]; if ((res = c.getMethod0(name, parameterTypes)) != null) { return res; } } // Not found return null; } ! private Constructor<T> getConstructor0(Class[] parameterTypes, int which) throws NoSuchMethodException { Constructor<T>[] constructors = privateGetDeclaredConstructors((which == Member.PUBLIC)); for (Constructor<T> constructor : constructors) { if (arrayContentsEq(parameterTypes, --- 2685,2714 ---- parameterTypes)) != null) { return res; } // Search superclass's methods if (!isInterface()) { ! Class<? super T> c = getSuperclass(); if (c != null) { if ((res = c.getMethod0(name, parameterTypes)) != null) { return res; } } } // Search superinterfaces' methods ! Class<?>[] interfaces = getInterfaces(); for (int i = 0; i < interfaces.length; i++) { ! Class<?> c = interfaces[i]; if ((res = c.getMethod0(name, parameterTypes)) != null) { return res; } } // Not found return null; } ! private Constructor<T> getConstructor0(Class<?>[] parameterTypes, int which) throws NoSuchMethodException { Constructor<T>[] constructors = privateGetDeclaredConstructors((which == Member.PUBLIC)); for (Constructor<T> constructor : constructors) { if (arrayContentsEq(parameterTypes,
*** 2773,2793 **** } private native Field[] getDeclaredFields0(boolean publicOnly); private native Method[] getDeclaredMethods0(boolean publicOnly); private native Constructor<T>[] getDeclaredConstructors0(boolean publicOnly); ! private native Class[] getDeclaredClasses0(); ! private static String argumentTypesToString(Class[] argTypes) { StringBuilder buf = new StringBuilder(); buf.append("("); if (argTypes != null) { for (int i = 0; i < argTypes.length; i++) { if (i > 0) { buf.append(", "); } ! Class c = argTypes[i]; buf.append((c == null) ? "null" : c.getName()); } } buf.append(")"); return buf.toString(); --- 2773,2793 ---- } private native Field[] getDeclaredFields0(boolean publicOnly); private native Method[] getDeclaredMethods0(boolean publicOnly); private native Constructor<T>[] getDeclaredConstructors0(boolean publicOnly); ! private native Class<?>[] getDeclaredClasses0(); ! private static String argumentTypesToString(Class<?>[] argTypes) { StringBuilder buf = new StringBuilder(); buf.append("("); if (argTypes != null) { for (int i = 0; i < argTypes.length; i++) { if (i > 0) { buf.append(", "); } ! Class<?> c = argTypes[i]; buf.append((c == null) ? "null" : c.getName()); } } buf.append(")"); return buf.toString();
*** 2856,2866 **** } return desiredAssertionStatus0(this); } // Retrieves the desired assertion status of this class from the VM ! private static native boolean desiredAssertionStatus0(Class clazz); /** * Returns true if and only if this class was declared as an enum in the * source code. * --- 2856,2866 ---- } return desiredAssertionStatus0(this); } // Retrieves the desired assertion status of this class from the VM ! private static native boolean desiredAssertionStatus0(Class<?> clazz); /** * Returns true if and only if this class was declared as an enum in the * source code. *
*** 2977,2987 **** if (universe == null) throw new IllegalArgumentException( getName() + " is not an enum type"); Map<String, T> m = new HashMap<String, T>(2 * universe.length); for (T constant : universe) ! m.put(((Enum)constant).name(), constant); enumConstantDirectory = m; } return enumConstantDirectory; } private volatile transient Map<String, T> enumConstantDirectory = null; --- 2977,2987 ---- if (universe == null) throw new IllegalArgumentException( getName() + " is not an enum type"); Map<String, T> m = new HashMap<String, T>(2 * universe.length); for (T constant : universe) ! m.put(((Enum<?>)constant).name(), constant); enumConstantDirectory = m; } return enumConstantDirectory; } private volatile transient Map<String, T> enumConstantDirectory = null;
*** 3075,3086 **** initAnnotationsIfNecessary(); return AnnotationParser.toArray(declaredAnnotations); } // Annotations cache ! private transient Map<Class, Annotation> annotations; ! private transient Map<Class, Annotation> declaredAnnotations; private synchronized void initAnnotationsIfNecessary() { clearCachesOnClassRedefinition(); if (annotations != null) return; --- 3075,3086 ---- initAnnotationsIfNecessary(); return AnnotationParser.toArray(declaredAnnotations); } // Annotations cache ! private transient Map<Class<? extends Annotation>, Annotation> annotations; ! private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations; private synchronized void initAnnotationsIfNecessary() { clearCachesOnClassRedefinition(); if (annotations != null) return;
*** 3088,3101 **** getRawAnnotations(), getConstantPool(), this); Class<?> superClass = getSuperclass(); if (superClass == null) { annotations = declaredAnnotations; } else { ! annotations = new HashMap<Class, Annotation>(); superClass.initAnnotationsIfNecessary(); ! for (Map.Entry<Class, Annotation> e : superClass.annotations.entrySet()) { ! Class annotationClass = e.getKey(); if (AnnotationType.getInstance(annotationClass).isInherited()) annotations.put(annotationClass, e.getValue()); } annotations.putAll(declaredAnnotations); } --- 3088,3101 ---- getRawAnnotations(), getConstantPool(), this); Class<?> superClass = getSuperclass(); if (superClass == null) { annotations = declaredAnnotations; } else { ! annotations = new HashMap<Class<? extends Annotation>, Annotation>(); superClass.initAnnotationsIfNecessary(); ! for (Map.Entry<Class<? extends Annotation>, Annotation> e : superClass.annotations.entrySet()) { ! Class<? extends Annotation> annotationClass = e.getKey(); if (AnnotationType.getInstance(annotationClass).isInherited()) annotations.put(annotationClass, e.getValue()); } annotations.putAll(declaredAnnotations); }