mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8345565
: Remove remaining SecurityManager motivated APIs from sun.reflect.util
Reviewed-by: mullan, rriggs, liach
This commit is contained in:
parent
97b8a09bda
commit
691e692149
10 changed files with 7 additions and 258 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -29,7 +29,6 @@ import java.lang.annotation.*;
|
|||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.GenericDeclaration;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
|
@ -41,7 +40,6 @@ import sun.reflect.annotation.TypeAnnotationParser;
|
|||
import sun.reflect.annotation.AnnotationType;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
import sun.reflect.misc.ReflectUtil;
|
||||
|
||||
/**
|
||||
* Implementation of {@code java.lang.reflect.TypeVariable} interface
|
||||
|
@ -135,13 +133,9 @@ public class TypeVariableImpl<D extends GenericDeclaration>
|
|||
* @since 1.5
|
||||
*/
|
||||
public D getGenericDeclaration() {
|
||||
if (genericDeclaration instanceof Class<?> c)
|
||||
ReflectUtil.checkPackageAccess(c);
|
||||
else if ((genericDeclaration instanceof Method) ||
|
||||
(genericDeclaration instanceof Constructor))
|
||||
ReflectUtil.conservativeCheckMemberAccess((Member)genericDeclaration);
|
||||
else
|
||||
throw new AssertionError("Unexpected kind of GenericDeclaration");
|
||||
assert genericDeclaration instanceof Class<?> ||
|
||||
genericDeclaration instanceof Method ||
|
||||
genericDeclaration instanceof Constructor : "Unexpected kind of GenericDeclaration";
|
||||
return genericDeclaration;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.misc;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public final class ConstructorUtil {
|
||||
|
||||
private ConstructorUtil() {
|
||||
}
|
||||
|
||||
public static Constructor<?> getConstructor(Class<?> cls, Class<?>[] params)
|
||||
throws NoSuchMethodException {
|
||||
ReflectUtil.checkPackageAccess(cls);
|
||||
return cls.getConstructor(params);
|
||||
}
|
||||
|
||||
public static Constructor<?>[] getConstructors(Class<?> cls) {
|
||||
ReflectUtil.checkPackageAccess(cls);
|
||||
return cls.getConstructors();
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.reflect.misc;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/*
|
||||
* Create a trampoline class.
|
||||
*/
|
||||
public final class FieldUtil {
|
||||
|
||||
private FieldUtil() {
|
||||
}
|
||||
|
||||
public static Field getField(Class<?> cls, String name)
|
||||
throws NoSuchFieldException {
|
||||
ReflectUtil.checkPackageAccess(cls);
|
||||
return cls.getField(name);
|
||||
}
|
||||
|
||||
public static Field[] getFields(Class<?> cls) {
|
||||
ReflectUtil.checkPackageAccess(cls);
|
||||
return cls.getFields();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -79,15 +79,9 @@ public final class MethodUtil extends SecureClassLoader {
|
|||
|
||||
public static Method getMethod(Class<?> cls, String name, Class<?>[] args)
|
||||
throws NoSuchMethodException {
|
||||
ReflectUtil.checkPackageAccess(cls);
|
||||
return cls.getMethod(name, args);
|
||||
}
|
||||
|
||||
public static Method[] getMethods(Class<?> cls) {
|
||||
ReflectUtil.checkPackageAccess(cls);
|
||||
return cls.getMethods();
|
||||
}
|
||||
|
||||
/*
|
||||
* Bounce through the trampoline.
|
||||
*/
|
||||
|
@ -140,7 +134,6 @@ public final class MethodUtil extends SecureClassLoader {
|
|||
throws ClassNotFoundException
|
||||
{
|
||||
// First, check if the class has already been loaded
|
||||
ReflectUtil.checkPackageAccess(name);
|
||||
Class<?> c = findLoadedClass(name);
|
||||
if (c == null) {
|
||||
try {
|
||||
|
|
|
@ -25,10 +25,6 @@
|
|||
|
||||
package sun.reflect.misc;
|
||||
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Proxy;
|
||||
import jdk.internal.reflect.Reflection;
|
||||
|
||||
public final class ReflectUtil {
|
||||
|
@ -67,112 +63,4 @@ public final class ReflectUtil {
|
|||
target == null ? null : target.getClass(),
|
||||
modifiers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
*/
|
||||
public static void conservativeCheckMemberAccess(Member m) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
*/
|
||||
public static void checkPackageAccess(Class<?> clazz) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing
|
||||
*/
|
||||
public static void checkPackageAccess(String name) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true.
|
||||
*/
|
||||
public static boolean isPackageAccessible(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false.
|
||||
*/
|
||||
public static boolean needsPackageAccessCheck(ClassLoader from, ClassLoader to) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing
|
||||
*/
|
||||
public static void checkProxyPackageAccess(Class<?> clazz) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
*/
|
||||
public static void checkProxyPackageAccess(ClassLoader ccl,
|
||||
Class<?>... interfaces) {
|
||||
}
|
||||
|
||||
// Note that bytecode instrumentation tools may exclude 'sun.*'
|
||||
// classes but not generated proxy classes and so keep it in com.sun.*
|
||||
public static final String PROXY_PACKAGE = "com.sun.proxy";
|
||||
|
||||
/**
|
||||
* Test if the given class is a proxy class that implements
|
||||
* non-public interface. Such proxy class may be in a non-restricted
|
||||
* package that bypasses checkPackageAccess.
|
||||
*/
|
||||
public static boolean isNonPublicProxyClass(Class<?> cls) {
|
||||
if (!Proxy.isProxyClass(cls)) {
|
||||
return false;
|
||||
}
|
||||
return !Modifier.isPublic(cls.getModifiers());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given method is a method declared in the proxy interface
|
||||
* implemented by the given proxy instance.
|
||||
*
|
||||
* @param proxy a proxy instance
|
||||
* @param method an interface method dispatched to a InvocationHandler
|
||||
*
|
||||
* @throws IllegalArgumentException if the given proxy or method is invalid.
|
||||
*/
|
||||
public static void checkProxyMethod(Object proxy, Method method) {
|
||||
// check if it is a valid proxy instance
|
||||
if (proxy == null || !Proxy.isProxyClass(proxy.getClass())) {
|
||||
throw new IllegalArgumentException("Not a Proxy instance");
|
||||
}
|
||||
if (Modifier.isStatic(method.getModifiers())) {
|
||||
throw new IllegalArgumentException("Can't handle static method");
|
||||
}
|
||||
|
||||
Class<?> c = method.getDeclaringClass();
|
||||
if (c == Object.class) {
|
||||
String name = method.getName();
|
||||
if (name.equals("hashCode") || name.equals("equals") || name.equals("toString")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSuperInterface(proxy.getClass(), c)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// disallow any method not declared in one of the proxy interfaces
|
||||
throw new IllegalArgumentException("Can't handle: " + method);
|
||||
}
|
||||
|
||||
private static boolean isSuperInterface(Class<?> c, Class<?> intf) {
|
||||
for (Class<?> i : c.getInterfaces()) {
|
||||
if (i == intf) {
|
||||
return true;
|
||||
}
|
||||
if (isSuperInterface(i, intf)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue