src/share/classes/java/lang/Class.java
Print this page
*** 360,397 ****
* any exception thrown by the constructor in a (checked) {@link
* java.lang.reflect.InvocationTargetException}.
*
* @return a newly allocated instance of the class represented by this
* object.
! * @exception IllegalAccessException if the class or its nullary
* constructor is not accessible.
! * @exception InstantiationException
* if this {@code Class} represents an abstract class,
* an interface, an array class, a primitive type, or void;
* or if the class has no nullary constructor;
* or if the instantiation fails for some other reason.
! * @exception ExceptionInInitializerError if the initialization
* provoked by this method fails.
! * @exception SecurityException
! * If a security manager, <i>s</i>, is present and any of the
! * following conditions is met:
! *
! * <ul>
! *
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.PUBLIC)} denies
! * creation of new instances of this class
! *
! * <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class
! *
! * </ul>
! *
*/
@CallerSensitive
public T newInstance()
throws InstantiationException, IllegalAccessException
{
--- 360,385 ----
* any exception thrown by the constructor in a (checked) {@link
* java.lang.reflect.InvocationTargetException}.
*
* @return a newly allocated instance of the class represented by this
* object.
! * @throws IllegalAccessException if the class or its nullary
* constructor is not accessible.
! * @throws InstantiationException
* if this {@code Class} represents an abstract class,
* an interface, an array class, a primitive type, or void;
* or if the class has no nullary constructor;
* or if the instantiation fails for some other reason.
! * @throws ExceptionInInitializerError if the initialization
* provoked by this method fails.
! * @throws SecurityException
! * If a security manager, <i>s</i>, is present and
! * the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class.
*/
@CallerSensitive
public T newInstance()
throws InstantiationException, IllegalAccessException
{
*** 979,998 ****
* class is a local or anonymous class immediately enclosed by a type
* declaration, instance initializer or static initializer.
*
* @return the immediately enclosing method of the underlying class, if
* that class is a local or anonymous class; otherwise {@code null}.
! * @exception SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(enclosingClass, Member.DECLARED)} denies
! * access to the methods within the enclosing class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the enclosing class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
--- 967,989 ----
* class is a local or anonymous class immediately enclosed by a type
* declaration, instance initializer or static initializer.
*
* @return the immediately enclosing method of the underlying class, if
* that class is a local or anonymous class; otherwise {@code null}.
! *
! * @throws SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> the caller's class loader is not the same as the
! * class loader of the enclosing class and invocation of
! * {@link SecurityManager#checkPermission
! * s.checkPermission} method with
! * {@code RuntimePermission("accessDeclaredMembers")}
! * denies access to the methods within the enclosing class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the enclosing class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
*** 1023,1039 ****
for(int i = 0; i < parameterClasses.length; i++)
parameterClasses[i] = toClass(parameterTypes[i]);
// Perform access check
Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
! // be very careful not to change the stack depth of this
! // checkMemberAccess call for security reasons
! // see java.lang.SecurityManager.checkMemberAccess
! //
! // Note that we need to do this on the enclosing class
enclosingCandidate.checkMemberAccess(Member.DECLARED,
Reflection.getCallerClass(), true);
/*
* Loop over all declared methods; match method name,
* number of and type of parameters, *and* return
* type. Matching return type is also necessary
* because of covariant returns, etc.
--- 1014,1027 ----
for(int i = 0; i < parameterClasses.length; i++)
parameterClasses[i] = toClass(parameterTypes[i]);
// Perform access check
Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
! if (System.getSecurityManager() != null) {
enclosingCandidate.checkMemberAccess(Member.DECLARED,
Reflection.getCallerClass(), true);
+ }
/*
* Loop over all declared methods; match method name,
* number of and type of parameters, *and* return
* type. Matching return type is also necessary
* because of covariant returns, etc.
*** 1135,1154 ****
* or anonymous class immediately enclosed by a type declaration,
* instance initializer or static initializer.
*
* @return the immediately enclosing constructor of the underlying class, if
* that class is a local or anonymous class; otherwise {@code null}.
! * @exception SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(enclosingClass, Member.DECLARED)} denies
! * access to the constructors within the enclosing class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the enclosing class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
--- 1123,1144 ----
* or anonymous class immediately enclosed by a type declaration,
* instance initializer or static initializer.
*
* @return the immediately enclosing constructor of the underlying class, if
* that class is a local or anonymous class; otherwise {@code null}.
! * @throws SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> the caller's class loader is not the same as the
! * class loader of the enclosing class and invocation of
! * {@link SecurityManager#checkPermission
! * s.checkPermission} method with
! * {@code RuntimePermission("accessDeclaredMembers")}
! * denies access to the constructors within the enclosing class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the enclosing class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
*** 1178,1194 ****
for(int i = 0; i < parameterClasses.length; i++)
parameterClasses[i] = toClass(parameterTypes[i]);
// Perform access check
Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
! // be very careful not to change the stack depth of this
! // checkMemberAccess call for security reasons
! // see java.lang.SecurityManager.checkMemberAccess
! //
! // Note that we need to do this on the enclosing class
enclosingCandidate.checkMemberAccess(Member.DECLARED,
Reflection.getCallerClass(), true);
/*
* Loop over all declared constructors; match number
* of and type of parameters.
*/
for(Constructor<?> c: enclosingCandidate.getDeclaredConstructors()) {
--- 1168,1181 ----
for(int i = 0; i < parameterClasses.length; i++)
parameterClasses[i] = toClass(parameterTypes[i]);
// Perform access check
Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
! if (System.getSecurityManager() != null) {
enclosingCandidate.checkMemberAccess(Member.DECLARED,
Reflection.getCallerClass(), true);
+ }
/*
* Loop over all declared constructors; match number
* of and type of parameters.
*/
for(Constructor<?> c: enclosingCandidate.getDeclaredConstructors()) {
*** 1456,1489 ****
* this {@code Class} object represents a primitive type, an array
* class, or void.
*
* @return the array of {@code Class} objects representing the public
* members of this class
! * @exception SecurityException
! * If a security manager, <i>s</i>, is present and any of the
! * following conditions is met:
! *
! * <ul>
! *
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.PUBLIC)} method
! * denies access to the classes within this class
! *
! * <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class
! *
! * </ul>
*
* @since JDK1.1
*/
@CallerSensitive
public Class<?>[] getClasses() {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), false);
// Privileged so this implementation can look at DECLARED classes,
// something the caller might not have privilege to do. The code here
// is allowed to look at DECLARED classes because (1) it does not hand
// out anything other than public members and (2) public member access
--- 1443,1467 ----
* this {@code Class} object represents a primitive type, an array
* class, or void.
*
* @return the array of {@code Class} objects representing the public
* members of this class
! * @throws SecurityException
! * If a security manager, <i>s</i>, is present and
! * the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class.
*
* @since JDK1.1
*/
@CallerSensitive
public Class<?>[] getClasses() {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), false);
+ }
// Privileged so this implementation can look at DECLARED classes,
// something the caller might not have privilege to do. The code here
// is allowed to look at DECLARED classes because (1) it does not hand
// out anything other than public members and (2) public member access
*** 1529,1562 ****
*
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
*
* @return the array of {@code Field} objects representing the
* public fields
! * @exception SecurityException
! * If a security manager, <i>s</i>, is present and any of the
! * following conditions is met:
! *
! * <ul>
! *
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.PUBLIC)} denies
! * access to the fields within this class
! *
! * <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class
! *
! * </ul>
*
* @since JDK1.1
*/
@CallerSensitive
public Field[] getFields() throws SecurityException {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
return copyFields(privateGetPublicFields(null));
}
/**
--- 1507,1531 ----
*
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
*
* @return the array of {@code Field} objects representing the
* public fields
! * @throws SecurityException
! * If a security manager, <i>s</i>, is present and
! * the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class.
*
* @since JDK1.1
*/
@CallerSensitive
public Field[] getFields() throws SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
+ }
return copyFields(privateGetPublicFields(null));
}
/**
*** 1578,1611 ****
*
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
*
* @return the array of {@code Method} objects representing the
* public methods of this class
! * @exception SecurityException
! * If a security manager, <i>s</i>, is present and any of the
! * following conditions is met:
! *
! * <ul>
! *
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.PUBLIC)} denies
! * access to the methods within this class
! *
! * <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class
! *
! * </ul>
*
* @since JDK1.1
*/
@CallerSensitive
public Method[] getMethods() throws SecurityException {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
return copyMethods(privateGetPublicMethods());
}
/**
--- 1547,1571 ----
*
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
*
* @return the array of {@code Method} objects representing the
* public methods of this class
! * @throws SecurityException
! * If a security manager, <i>s</i>, is present and
! * the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class.
*
* @since JDK1.1
*/
@CallerSensitive
public Method[] getMethods() throws SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
+ }
return copyMethods(privateGetPublicMethods());
}
/**
*** 1625,1658 ****
* different classes, which would violate the type guarantees of
* {@code Constructor<T>[]}.
*
* @return the array of {@code Constructor} objects representing the
* public constructors of this class
! * @exception SecurityException
! * If a security manager, <i>s</i>, is present and any of the
! * following conditions is met:
! *
! * <ul>
! *
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.PUBLIC)} denies
! * access to the constructors within this class
! *
! * <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class
! *
! * </ul>
*
* @since JDK1.1
*/
@CallerSensitive
public Constructor<?>[] getConstructors() throws SecurityException {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
return copyConstructors(privateGetDeclaredConstructors(true));
}
/**
--- 1585,1609 ----
* different classes, which would violate the type guarantees of
* {@code Constructor<T>[]}.
*
* @return the array of {@code Constructor} objects representing the
* public constructors of this class
! * @throws SecurityException
! * If a security manager, <i>s</i>, is present and
! * the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class.
*
* @since JDK1.1
*/
@CallerSensitive
public Constructor<?>[] getConstructors() throws SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
+ }
return copyConstructors(privateGetDeclaredConstructors(true));
}
/**
*** 1678,1715 ****
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
*
* @param name the field name
* @return the {@code Field} object of this class specified by
* {@code name}
! * @exception NoSuchFieldException if a field with the specified name is
* not found.
! * @exception NullPointerException if {@code name} is {@code null}
! * @exception SecurityException
! * If a security manager, <i>s</i>, is present and any of the
! * following conditions is met:
! *
! * <ul>
! *
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.PUBLIC)} denies
! * access to the field
! *
! * <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class
! *
! * </ul>
*
* @since JDK1.1
*/
@CallerSensitive
public Field getField(String name)
throws NoSuchFieldException, SecurityException {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
Field field = getField0(name);
if (field == null) {
throw new NoSuchFieldException(name);
}
return field;
--- 1629,1657 ----
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
*
* @param name the field name
* @return the {@code Field} object of this class specified by
* {@code name}
! * @throws NoSuchFieldException if a field with the specified name is
* not found.
! * @throws NullPointerException if {@code name} is {@code null}
! * @throws SecurityException
! * If a security manager, <i>s</i>, is present and
! * the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class.
*
* @since JDK1.1
*/
@CallerSensitive
public Field getField(String name)
throws NoSuchFieldException, SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
+ }
Field field = getField0(name);
if (field == null) {
throw new NoSuchFieldException(name);
}
return field;
*** 1761,1798 ****
*
* @param name the name of the method
* @param parameterTypes the list of parameters
* @return the {@code Method} object that matches the specified
* {@code name} and {@code parameterTypes}
! * @exception NoSuchMethodException if a matching method is not found
* or if the name is "<init>"or "<clinit>".
! * @exception NullPointerException if {@code name} is {@code null}
! * @exception SecurityException
! * If a security manager, <i>s</i>, is present and any of the
! * following conditions is met:
! *
! * <ul>
! *
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.PUBLIC)} denies
! * access to the method
! *
! * <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class
! *
! * </ul>
*
* @since JDK1.1
*/
@CallerSensitive
public Method getMethod(String name, Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
Method method = getMethod0(name, parameterTypes);
if (method == null) {
throw new NoSuchMethodException(getName() + "." + name + argumentTypesToString(parameterTypes));
}
return method;
--- 1703,1731 ----
*
* @param name the name of the method
* @param parameterTypes the list of parameters
* @return the {@code Method} object that matches the specified
* {@code name} and {@code parameterTypes}
! * @throws NoSuchMethodException if a matching method is not found
* or if the name is "<init>"or "<clinit>".
! * @throws NullPointerException if {@code name} is {@code null}
! * @throws SecurityException
! * If a security manager, <i>s</i>, is present and
! * the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class.
*
* @since JDK1.1
*/
@CallerSensitive
public Method getMethod(String name, Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
+ }
Method method = getMethod0(name, parameterTypes);
if (method == null) {
throw new NoSuchMethodException(getName() + "." + name + argumentTypesToString(parameterTypes));
}
return method;
*** 1815,1850 ****
* types match those specified by {@code parameterTypes}.
*
* @param parameterTypes the parameter array
* @return the {@code Constructor} object of the public constructor that
* matches the specified {@code parameterTypes}
! * @exception NoSuchMethodException if a matching method is not found.
! * @exception SecurityException
! * If a security manager, <i>s</i>, is present and any of the
! * following conditions is met:
! *
! * <ul>
! *
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.PUBLIC)} denies
! * access to the constructor
! *
! * <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class
! *
! * </ul>
*
* @since JDK1.1
*/
@CallerSensitive
public Constructor<T> getConstructor(Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
return getConstructor0(parameterTypes, Member.PUBLIC);
}
/**
--- 1748,1774 ----
* types match those specified by {@code parameterTypes}.
*
* @param parameterTypes the parameter array
* @return the {@code Constructor} object of the public constructor that
* matches the specified {@code parameterTypes}
! * @throws NoSuchMethodException if a matching method is not found.
! * @throws SecurityException
! * If a security manager, <i>s</i>, is present and
! * the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
! * of this class.
*
* @since JDK1.1
*/
@CallerSensitive
public Constructor<T> getConstructor(Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.PUBLIC, Reflection.getCallerClass(), true);
+ }
return getConstructor0(parameterTypes, Member.PUBLIC);
}
/**
*** 1857,1876 ****
* interfaces as members, or if this {@code Class} object represents a
* primitive type, an array class, or void.
*
* @return the array of {@code Class} objects representing all the
* declared members of this class
! * @exception SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.DECLARED)} denies
! * access to the declared classes within this class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
--- 1781,1802 ----
* interfaces as members, or if this {@code Class} object represents a
* primitive type, an array class, or void.
*
* @return the array of {@code Class} objects representing all the
* declared members of this class
! * @throws SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> the caller's class loader is not the same as the
! * class loader of this class and invocation of
! * {@link SecurityManager#checkPermission
! * s.checkPermission} method with
! * {@code RuntimePermission("accessDeclaredMembers")}
! * denies access to the declared classes within this class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
*** 1880,1890 ****
--- 1806,1818 ----
*
* @since JDK1.1
*/
@CallerSensitive
public Class<?>[] getDeclaredClasses() throws SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), false);
+ }
return getDeclaredClasses0();
}
/**
*** 1899,1918 ****
*
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
*
* @return the array of {@code Field} objects representing all the
* declared fields of this class
! * @exception SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.DECLARED)} denies
! * access to the declared fields within this class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
--- 1827,1848 ----
*
* <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
*
* @return the array of {@code Field} objects representing all the
* declared fields of this class
! * @throws SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> the caller's class loader is not the same as the
! * class loader of this class and invocation of
! * {@link SecurityManager#checkPermission
! * s.checkPermission} method with
! * {@code RuntimePermission("accessDeclaredMembers")}
! * denies access to the declared fields within this class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
*** 1922,1932 ****
--- 1852,1864 ----
*
* @since JDK1.1
*/
@CallerSensitive
public Field[] getDeclaredFields() throws SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), true);
+ }
return copyFields(privateGetDeclaredFields(false));
}
/**
*** 1945,1964 ****
*
* <p> See <em>The Java Language Specification</em>, section 8.2.
*
* @return the array of {@code Method} objects representing all the
* declared methods of this class
! * @exception SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.DECLARED)} denies
! * access to the declared methods within this class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
--- 1877,1898 ----
*
* <p> See <em>The Java Language Specification</em>, section 8.2.
*
* @return the array of {@code Method} objects representing all the
* declared methods of this class
! * @throws SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> the caller's class loader is not the same as the
! * class loader of this class and invocation of
! * {@link SecurityManager#checkPermission
! * s.checkPermission} method with
! * {@code RuntimePermission("accessDeclaredMembers")}
! * denies access to the declared methods within this class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
*** 1968,1978 ****
--- 1902,1914 ----
*
* @since JDK1.1
*/
@CallerSensitive
public Method[] getDeclaredMethods() throws SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), true);
+ }
return copyMethods(privateGetDeclaredMethods(false));
}
/**
*** 1988,2007 ****
*
* <p> See <em>The Java Language Specification</em>, section 8.2.
*
* @return the array of {@code Constructor} objects representing all the
* declared constructors of this class
! * @exception SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.DECLARED)} denies
! * access to the declared constructors within this class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
--- 1924,1945 ----
*
* <p> See <em>The Java Language Specification</em>, section 8.2.
*
* @return the array of {@code Constructor} objects representing all the
* declared constructors of this class
! * @throws SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> the caller's class loader is not the same as the
! * class loader of this class and invocation of
! * {@link SecurityManager#checkPermission
! * s.checkPermission} method with
! * {@code RuntimePermission("accessDeclaredMembers")}
! * denies access to the declared constructors within this class
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
*** 2011,2021 ****
--- 1949,1961 ----
*
* @since JDK1.1
*/
@CallerSensitive
public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), true);
+ }
return copyConstructors(privateGetDeclaredConstructors(false));
}
/**
*** 2026,2048 ****
* will not reflect the {@code length} field of an array class.
*
* @param name the name of the field
* @return the {@code Field} object for the specified field in this
* class
! * @exception NoSuchFieldException if a field with the specified name is
* not found.
! * @exception NullPointerException if {@code name} is {@code null}
! * @exception SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.DECLARED)} denies
! * access to the declared field
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
--- 1966,1990 ----
* will not reflect the {@code length} field of an array class.
*
* @param name the name of the field
* @return the {@code Field} object for the specified field in this
* class
! * @throws NoSuchFieldException if a field with the specified name is
* not found.
! * @throws NullPointerException if {@code name} is {@code null}
! * @throws SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> the caller's class loader is not the same as the
! * class loader of this class and invocation of
! * {@link SecurityManager#checkPermission
! * s.checkPermission} method with
! * {@code RuntimePermission("accessDeclaredMembers")}
! * denies access to the declared field
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
*** 2053,2063 ****
--- 1995,2007 ----
* @since JDK1.1
*/
@CallerSensitive
public Field getDeclaredField(String name)
throws NoSuchFieldException, SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), true);
+ }
Field field = searchFields(privateGetDeclaredFields(false), name);
if (field == null) {
throw new NoSuchFieldException(name);
}
return field;
*** 2080,2101 ****
*
* @param name the name of the method
* @param parameterTypes the parameter array
* @return the {@code Method} object for the method of this class
* matching the specified name and parameters
! * @exception NoSuchMethodException if a matching method is not found.
! * @exception NullPointerException if {@code name} is {@code null}
! * @exception SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.DECLARED)} denies
! * access to the declared method
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
--- 2024,2047 ----
*
* @param name the name of the method
* @param parameterTypes the parameter array
* @return the {@code Method} object for the method of this class
* matching the specified name and parameters
! * @throws NoSuchMethodException if a matching method is not found.
! * @throws NullPointerException if {@code name} is {@code null}
! * @throws SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> the caller's class loader is not the same as the
! * class loader of this class and invocation of
! * {@link SecurityManager#checkPermission
! * s.checkPermission} method with
! * {@code RuntimePermission("accessDeclaredMembers")}
! * denies access to the declared method
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
*** 2106,2116 ****
--- 2052,2064 ----
* @since JDK1.1
*/
@CallerSensitive
public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), true);
+ }
Method method = searchMethods(privateGetDeclaredMethods(false), name, parameterTypes);
if (method == null) {
throw new NoSuchMethodException(getName() + "." + name + argumentTypesToString(parameterTypes));
}
return method;
*** 2129,2149 ****
* include the explicit enclosing instance as the first parameter.
*
* @param parameterTypes the parameter array
* @return The {@code Constructor} object for the constructor with the
* specified parameter list
! * @exception NoSuchMethodException if a matching method is not found.
! * @exception SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> invocation of
! * {@link SecurityManager#checkMemberAccess
! * s.checkMemberAccess(this, Member.DECLARED)} denies
! * access to the declared constructor
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
--- 2077,2099 ----
* include the explicit enclosing instance as the first parameter.
*
* @param parameterTypes the parameter array
* @return The {@code Constructor} object for the constructor with the
* specified parameter list
! * @throws NoSuchMethodException if a matching method is not found.
! * @throws SecurityException
* If a security manager, <i>s</i>, is present and any of the
* following conditions is met:
*
* <ul>
*
! * <li> the caller's class loader is not the same as the
! * class loader of this class and invocation of
! * {@link SecurityManager#checkPermission
! * s.checkPermission} method with
! * {@code RuntimePermission("accessDeclaredMembers")}
! * denies access to the declared constructor
*
* <li> the caller's class loader is not the same as or an
* ancestor of the class loader for the current class and
* invocation of {@link SecurityManager#checkPackageAccess
* s.checkPackageAccess()} denies access to the package
*** 2154,2164 ****
--- 2104,2116 ----
* @since JDK1.1
*/
@CallerSensitive
public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
+ if (System.getSecurityManager() != null) {
checkMemberAccess(Member.DECLARED, Reflection.getCallerClass(), true);
+ }
return getConstructor0(parameterTypes, Member.DECLARED);
}
/**
* Finds a resource with a given name. The rules for searching resources
*** 2304,2321 ****
* Return the Virtual Machine's Class object for the named
* primitive type.
*/
static native Class<?> getPrimitiveClass(String name);
- private static boolean isCheckMemberAccessOverridden(SecurityManager smgr) {
- if (smgr.getClass() == SecurityManager.class) return false;
-
- Class<?>[] paramTypes = new Class<?>[] {Class.class, int.class};
- return smgr.getClass().getMethod0("checkMemberAccess", paramTypes).
- getDeclaringClass() != SecurityManager.class;
- }
-
/*
* Check if client is allowed to access members. If access is denied,
* throw a SecurityException.
*
* This method also enforces package access.
--- 2256,2265 ----
*** 2324,2347 ****
* control.
*/
private void checkMemberAccess(int which, Class<?> caller, boolean checkProxyInterfaces) {
final SecurityManager s = System.getSecurityManager();
if (s != null) {
final ClassLoader ccl = ClassLoader.getClassLoader(caller);
final ClassLoader cl = getClassLoader0();
- if (!isCheckMemberAccessOverridden(s)) {
- // Inlined SecurityManager.checkMemberAccess
if (which != Member.PUBLIC) {
if (ccl != cl) {
s.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
}
- } else {
- // Don't refactor; otherwise break the stack depth for
- // checkMemberAccess of subclasses of SecurityManager as specified.
- s.checkMemberAccess(this, which);
- }
this.checkPackageAccess(ccl, checkProxyInterfaces);
}
}
/*
--- 2268,2289 ----
* control.
*/
private void checkMemberAccess(int which, Class<?> caller, boolean checkProxyInterfaces) {
final SecurityManager s = System.getSecurityManager();
if (s != null) {
+ /* Default policy allows access to all {@link Member#PUBLIC} members,
+ * as well as access to classes that have the same class loader as the caller.
+ * In all other cases, it requires RuntimePermission("accessDeclaredMembers")
+ * permission.
+ */
final ClassLoader ccl = ClassLoader.getClassLoader(caller);
final ClassLoader cl = getClassLoader0();
if (which != Member.PUBLIC) {
if (ccl != cl) {
s.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION);
}
}
this.checkPackageAccess(ccl, checkProxyInterfaces);
}
}
/*