< prev index next >
src/java.base/share/classes/java/lang/Class.java
Print this page
*** 286,296 ****
*/
@CallerSensitive
public static Class<?> forName(String className)
throws ClassNotFoundException {
Class<?> caller = Reflection.getCallerClass();
! return forName0(className, true, ClassLoader.getClassLoader(caller), caller);
}
/**
* Returns the {@code Class} object associated with the class or
--- 286,300 ----
*/
@CallerSensitive
public static Class<?> forName(String className)
throws ClassNotFoundException {
Class<?> caller = Reflection.getCallerClass();
! Class<?> c = forName0(className, true, ClassLoader.getClassLoader(caller), caller);
! if (c.isValueClass()) {
! throw new ClassNotFoundException(className + " is a derived value class");
! }
! return c;
}
/**
* Returns the {@code Class} object associated with the class or
*** 369,383 ****
sm.checkPermission(
SecurityConstants.GET_CLASSLOADER_PERMISSION);
}
}
}
! return forName0(name, initialize, loader, caller);
}
/** Called after security check for system loader access checks have been made. */
! private static native Class<?> forName0(String name, boolean initialize,
ClassLoader loader,
Class<?> caller)
throws ClassNotFoundException;
--- 373,391 ----
sm.checkPermission(
SecurityConstants.GET_CLASSLOADER_PERMISSION);
}
}
}
! Class<?> c = forName0(name, initialize, loader, caller);
! if (c.isValueClass()) {
! throw new ClassNotFoundException(name + " is a derived value class");
! }
! return c;
}
/** Called after security check for system loader access checks have been made. */
! static native Class<?> forName0(String name, boolean initialize,
ClassLoader loader,
Class<?> caller)
throws ClassNotFoundException;
*** 441,454 ****
}
}
PrivilegedAction<ClassLoader> pa = module::getClassLoader;
ClassLoader cl = AccessController.doPrivileged(pa);
if (cl != null) {
! return cl.loadClass(module, name);
} else {
! return BootLoader.loadClass(module, name);
}
}
/**
* Creates a new instance of the class represented by this {@code Class}
--- 449,484 ----
}
}
PrivilegedAction<ClassLoader> pa = module::getClassLoader;
ClassLoader cl = AccessController.doPrivileged(pa);
+ Class<?> c;
if (cl != null) {
! c = cl.loadClass(module, name);
} else {
! c = BootLoader.loadClass(module, name);
! }
!
! return c != null && !c.isValueClass() ? c : null;
! }
!
! boolean isValueClass() {
! Class<?> c = this;
! while (c.isArray()) {
! c = c.getComponentType();
! }
!
! // This could call MinimalValueTypes_1_0::isValueType or check ACC_VALUE.
! // For now, check if it is a subtype of __Value to avoid
! // initializing MinimalValueTypes_1_0 class during early startup.
! return __Value.class.isAssignableFrom(c) && c != __Value.class;
! }
!
! private void ensureNotValueClass() {
! if (this.isValueClass()) {
! throw new UnsupportedOperationException("cannot reflect on derived value type "
! + this.getName());
}
}
/**
* Creates a new instance of the class represented by this {@code Class}
*** 506,515 ****
--- 536,547 ----
@CallerSensitive
@Deprecated(since="9")
public T newInstance()
throws InstantiationException, IllegalAccessException
{
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), false);
}
*** 1235,1244 ****
--- 1267,1278 ----
for(int i = 0; i < parameterClasses.length; i++)
parameterClasses[i] = toClass(parameterTypes[i]);
// Perform access check
final Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
+ enclosingCandidate.ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
enclosingCandidate.checkMemberAccess(sm, Member.DECLARED,
Reflection.getCallerClass(), true);
}
*** 1391,1400 ****
--- 1425,1436 ----
for(int i = 0; i < parameterClasses.length; i++)
parameterClasses[i] = toClass(parameterTypes[i]);
// Perform access check
final Class<?> enclosingCandidate = enclosingInfo.getEnclosingClass();
+ enclosingCandidate.ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
enclosingCandidate.checkMemberAccess(sm, Member.DECLARED,
Reflection.getCallerClass(), true);
}
*** 1687,1696 ****
--- 1723,1734 ----
*
* @since 1.1
*/
@CallerSensitive
public Class<?>[] getClasses() {
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), false);
}
*** 1756,1765 ****
--- 1794,1805 ----
* @jls 8.2 Class Members
* @jls 8.3 Field Declarations
*/
@CallerSensitive
public Field[] getFields() throws SecurityException {
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
}
return copyFields(privateGetPublicFields(null));
*** 1846,1855 ****
--- 1886,1897 ----
* @jls 8.4 Method Declarations
* @since 1.1
*/
@CallerSensitive
public Method[] getMethods() throws SecurityException {
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
}
return copyMethods(privateGetPublicMethods());
*** 1885,1894 ****
--- 1927,1938 ----
*
* @since 1.1
*/
@CallerSensitive
public Constructor<?>[] getConstructors() throws SecurityException {
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
}
return copyConstructors(privateGetDeclaredConstructors(true));
*** 1938,1947 ****
--- 1982,1993 ----
* @jls 8.3 Field Declarations
*/
@CallerSensitive
public Field getField(String name)
throws NoSuchFieldException, SecurityException {
+ ensureNotValueClass();
+
Objects.requireNonNull(name);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
}
*** 2047,2056 ****
--- 2093,2104 ----
* @since 1.1
*/
@CallerSensitive
public Method getMethod(String name, Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
+ ensureNotValueClass();
+
Objects.requireNonNull(name);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
}
*** 2111,2120 ****
--- 2159,2170 ----
*/
@CallerSensitive
public Constructor<T> getConstructor(Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException
{
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true);
}
return getReflectionFactory().copyConstructor(
*** 2157,2166 ****
--- 2207,2218 ----
*
* @since 1.1
*/
@CallerSensitive
public Class<?>[] getDeclaredClasses() throws SecurityException {
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), false);
}
return getDeclaredClasses0();
*** 2209,2218 ****
--- 2261,2272 ----
* @jls 8.2 Class Members
* @jls 8.3 Field Declarations
*/
@CallerSensitive
public Field[] getDeclaredFields() throws SecurityException {
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
}
return copyFields(privateGetDeclaredFields(false));
*** 2271,2280 ****
--- 2325,2336 ----
* @jls 8.4 Method Declarations
* @since 1.1
*/
@CallerSensitive
public Method[] getDeclaredMethods() throws SecurityException {
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
}
return copyMethods(privateGetDeclaredMethods(false));
*** 2319,2328 ****
--- 2375,2386 ----
*
* @since 1.1
*/
@CallerSensitive
public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
}
return copyConstructors(privateGetDeclaredConstructors(false));
*** 2370,2379 ****
--- 2428,2439 ----
* @jls 8.3 Field Declarations
*/
@CallerSensitive
public Field getDeclaredField(String name)
throws NoSuchFieldException, SecurityException {
+ ensureNotValueClass();
+
Objects.requireNonNull(name);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
}
*** 2434,2443 ****
--- 2494,2505 ----
* @since 1.1
*/
@CallerSensitive
public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException {
+ ensureNotValueClass();
+
Objects.requireNonNull(name);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
}
*** 2489,2498 ****
--- 2551,2562 ----
*/
@CallerSensitive
public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
throws NoSuchMethodException, SecurityException
{
+ ensureNotValueClass();
+
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
}
< prev index next >