Skip to content

Commit

Permalink
8344891: Remove uses of sun.misc.ReflectUtil in java.desktop
Browse files Browse the repository at this point in the history
Reviewed-by: kizune, azvegint
  • Loading branch information
prrace committed Nov 23, 2024
1 parent 822a155 commit 7be94d0
Show file tree
Hide file tree
Showing 24 changed files with 9 additions and 68 deletions.
2 changes: 0 additions & 2 deletions src/java.desktop/macosx/classes/com/apple/laf/AquaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import sun.awt.AppContext;

import sun.lwawt.macosx.CPlatformWindow;
import sun.reflect.misc.ReflectUtil;
import sun.swing.SwingUtilities2;

import com.apple.laf.AquaImageFactory.SlicedImageControl;
Expand Down Expand Up @@ -174,7 +173,6 @@ static class RecyclableSingletonFromDefaultConstructor<T> extends RecyclableSing
@SuppressWarnings("deprecation")
T getInstance() {
try {
ReflectUtil.checkPackageAccess(clazz);
return clazz.newInstance();
} catch (ReflectiveOperationException ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
*/
package com.sun.beans.finder;

import static sun.reflect.misc.ReflectUtil.checkPackageAccess;

/**
* This is utility class that provides {@code static} methods
* to find a class with the specified name using the specified class loader.
Expand Down Expand Up @@ -56,7 +54,6 @@ public final class ClassFinder {
* @see Thread#getContextClassLoader()
*/
public static Class<?> findClass(String name) throws ClassNotFoundException {
checkPackageAccess(name);
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
Expand Down Expand Up @@ -95,7 +92,6 @@ public static Class<?> findClass(String name) throws ClassNotFoundException {
* @see Class#forName(String,boolean,ClassLoader)
*/
public static Class<?> findClass(String name, ClassLoader loader) throws ClassNotFoundException {
checkPackageAccess(name);
if (loader != null) {
try {
return Class.forName(name, false, loader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.lang.reflect.Modifier;

import static com.sun.beans.util.Cache.Kind.SOFT;
import static sun.reflect.misc.ReflectUtil.isPackageAccessible;

/**
* This utility class provides {@code static} methods
Expand Down Expand Up @@ -81,7 +80,7 @@ public static Constructor<?> findConstructor(Class<?> type, Class<?>...args) thr
throw new NoSuchMethodException("Abstract class cannot be instantiated: "
+ type.getName());
}
if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
if (!Modifier.isPublic(type.getModifiers())) {
throw new NoSuchMethodException("Class is not accessible: " + type.getName());
}
PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import static sun.reflect.misc.ReflectUtil.isPackageAccessible;

/**
* This utility class provides {@code static} methods
* to find a public field with specified name
Expand Down Expand Up @@ -62,7 +60,7 @@ public static Field findField(Class<?> type, String name) throws NoSuchFieldExce
throw new NoSuchFieldException("Field '" + name + "' is not public");
}
type = field.getDeclaringClass();
if (!Modifier.isPublic(type.getModifiers()) || !isPackageAccessible(type)) {
if (!Modifier.isPublic(type.getModifiers())) {
throw new NoSuchFieldException("Field '" + name + "' is not accessible");
}
return field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.Arrays;

import static com.sun.beans.util.Cache.Kind.SOFT;
import static sun.reflect.misc.ReflectUtil.isPackageAccessible;

/**
* This utility class provides {@code static} methods
Expand Down Expand Up @@ -79,7 +78,7 @@ public static Method findMethod(Class<?> type, String name, Class<?>...args) thr

try {
Method method = CACHE.get(signature);
return (method == null) || isPackageAccessible(method.getDeclaringClass()) ? method : CACHE.create(signature);
return (method == null) ? method : CACHE.create(signature);
}
catch (SignatureException exception) {
throw exception.toNoSuchMethodException("Method '" + name + "' is not found");
Expand Down Expand Up @@ -138,7 +137,7 @@ public static Method findAccessibleMethod(Method method) throws NoSuchMethodExce
if (!FinderUtils.isExported(type)) {
throw new NoSuchMethodException("Method '" + method.getName() + "' is not accessible");
}
if (Modifier.isPublic(type.getModifiers()) && isPackageAccessible(type)) {
if (Modifier.isPublic(type.getModifiers())) {
return method;
}
if (Modifier.isStatic(method.getModifiers())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

import com.sun.beans.util.Cache;

import static sun.reflect.misc.ReflectUtil.checkPackageAccess;

public final class ClassInfo {
private static final ClassInfo DEFAULT = new ClassInfo(null);
private static final Cache<Class<?>,ClassInfo> CACHE
Expand All @@ -48,7 +46,6 @@ public static ClassInfo get(Class<?> type) {
return DEFAULT;
}
try {
checkPackageAccess(type);
return CACHE.get(type);
} catch (SecurityException exception) {
return DEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import javax.sound.midi.Soundbank;
import javax.sound.midi.spi.SoundbankReader;

import sun.reflect.misc.ReflectUtil;

/**
* JarSoundbankReader is used to read soundbank object from jar files.
*
Expand Down Expand Up @@ -95,7 +93,6 @@ public Soundbank getSoundbank(URL url)
try {
Class<?> c = Class.forName(line.trim(), false, ucl);
if (Soundbank.class.isAssignableFrom(c)) {
ReflectUtil.checkPackageAccess(c);
Object o = c.newInstance();
soundbanks.add((Soundbank) o);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.*;
import java.lang.reflect.*;
import java.util.Objects;
import sun.reflect.misc.*;
import sun.reflect.misc.MethodUtil;


/**
Expand Down Expand Up @@ -222,9 +222,6 @@ static void invokeStatement(Object instance, String methodName, Object[] args, E
// Write out the properties of this instance.
private void initBean(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
for (Field field : type.getFields()) {
if (!ReflectUtil.isPackageAccessible(field.getDeclaringClass())) {
continue;
}
int mod = field.getModifiers();
if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || Modifier.isTransient(mod)) {
continue;
Expand Down
2 changes: 0 additions & 2 deletions src/java.desktop/share/classes/java/beans/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.lang.reflect.Method;

import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;

/**
* The {@code EventHandler} class provides
Expand Down Expand Up @@ -691,7 +690,6 @@ public static <T> T create(Class<T> listenerInterface,
}

private static ClassLoader getClassLoader(Class<?> type) {
ReflectUtil.checkPackageAccess(type);
ClassLoader loader = type.getClassLoader();
if (loader == null) {
loader = Thread.currentThread().getContextClassLoader(); // avoid use of BCP
Expand Down
4 changes: 0 additions & 4 deletions src/java.desktop/share/classes/java/beans/Introspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import com.sun.beans.introspect.PropertyInfo;
import jdk.internal.access.JavaBeansAccess;
import jdk.internal.access.SharedSecrets;
import sun.reflect.misc.ReflectUtil;

/**
* The Introspector class provides a standard way for tools to learn about
Expand Down Expand Up @@ -186,9 +185,6 @@ public String[] getConstructorPropertiesValue(Constructor<?> ctr) {
public static BeanInfo getBeanInfo(Class<?> beanClass)
throws IntrospectionException
{
if (!ReflectUtil.isPackageAccessible(beanClass)) {
return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
}
ThreadGroupContext context = ThreadGroupContext.getContext();
BeanInfo beanInfo = context.getBeanInfo(beanClass);
if (beanInfo == null) {
Expand Down
4 changes: 1 addition & 3 deletions src/java.desktop/share/classes/java/beans/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@

import sun.swing.PrintColorUIResource;

import static sun.reflect.misc.ReflectUtil.isPackageAccessible;

/*
* Like the {@code Introspector}, the {@code MetaData} class
* contains <em>meta</em> objects that describe the way
Expand Down Expand Up @@ -749,7 +747,7 @@ protected Expression instantiate(Object oldInstance, Encoder out) {

static class StaticFieldsPersistenceDelegate extends PersistenceDelegate {
protected void installFields(Encoder out, Class<?> cls) {
if (Modifier.isPublic(cls.getModifiers()) && isPackageAccessible(cls)) {
if (Modifier.isPublic(cls.getModifiers())) {
Field[] fields = cls.getFields();
for(int i = 0; i < fields.length; i++) {
Field field = fields[i];
Expand Down
4 changes: 1 addition & 3 deletions src/java.desktop/share/classes/java/beans/MethodRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;

import static sun.reflect.misc.ReflectUtil.isPackageAccessible;

final class MethodRef {
private String signature;
private SoftReference<Method> methodRef;
Expand Down Expand Up @@ -68,7 +66,7 @@ Method get() {
}
this.methodRef = new SoftReference<>(method);
}
return isPackageAccessible(method.getDeclaringClass()) ? method : null;
return method;
}

private static Method find(Class<?> type, String signature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Map.Entry;

import com.sun.beans.introspect.PropertyInfo;
import sun.reflect.misc.ReflectUtil;

/**
* A PropertyDescriptor describes one property that a Java Bean
Expand Down Expand Up @@ -467,8 +466,7 @@ public PropertyEditor createPropertyEditor(Object bean) {
Object editor = null;

final Class<?> cls = getPropertyEditorClass();
if (cls != null && PropertyEditor.class.isAssignableFrom(cls)
&& ReflectUtil.isPackageAccessible(cls)) {
if (cls != null && PropertyEditor.class.isAssignableFrom(cls)) {
Constructor<?> ctor = null;
if (bean != null) {
try {
Expand Down
7 changes: 0 additions & 7 deletions src/java.desktop/share/classes/java/beans/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import com.sun.beans.finder.MethodFinder;
import sun.reflect.misc.MethodUtil;

import static sun.reflect.misc.ReflectUtil.checkPackageAccess;

/**
* A {@code Statement} object represents a primitive statement
* in which a single method is applied to a target and
Expand Down Expand Up @@ -189,13 +187,8 @@ Object invoke() throws Exception {
// Class.forName(String className) won't load classes outside
// of core from a class inside core. Special
// case this method.
// checkPackageAccess(name) will be called by ClassFinder
return ClassFinder.resolveClass(name, this.loader);
}
// The 3 args Class.forName(String className, boolean, classloader)
// requires getClassLoader permission, but we will be stricter and
// will require access to the package as well.
checkPackageAccess(name);
}
Class<?>[] argClasses = new Class<?>[arguments.length];
for(int i = 0; i < arguments.length; i++) {
Expand Down
1 change: 0 additions & 1 deletion src/java.desktop/share/classes/javax/print/SimpleDoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ public SimpleDoc(Object printData,
Class<?> repClass = null;
try {
String className = flavor.getRepresentationClassName();
sun.reflect.misc.ReflectUtil.checkPackageAccess(className);
repClass = Class.forName(className, false,
Thread.currentThread().getContextClassLoader());
} catch (Throwable e) {
Expand Down
3 changes: 0 additions & 3 deletions src/java.desktop/share/classes/javax/swing/JEditorPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;

import sun.reflect.misc.ReflectUtil;

/**
* A text component to edit various kinds of content.
* You can find how-to information and examples of using editor panes in
Expand Down Expand Up @@ -1238,7 +1236,6 @@ public static EditorKit createEditorKitForContentType(String type) {
try {
Class<?> c;
if (loader != null) {
ReflectUtil.checkPackageAccess(classname);
c = loader.loadClass(classname);
} else {
// Will only happen if developer has invoked
Expand Down
2 changes: 0 additions & 2 deletions src/java.desktop/share/classes/javax/swing/JTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@

import sun.awt.AWTAccessor;
import sun.awt.AWTAccessor.MouseEventAccessor;
import sun.reflect.misc.ReflectUtil;
import sun.swing.PrintingStatus;
import sun.swing.SwingUtilities2;
import sun.swing.SwingUtilities2.Section;
Expand Down Expand Up @@ -5585,7 +5584,6 @@ public Component getTableCellEditorComponent(JTable table, Object value,
if (type == Object.class) {
type = String.class;
}
ReflectUtil.checkPackageAccess(type);
SwingUtilities2.checkAccess(type.getModifiers());
constructor = type.getConstructor(argTypes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package javax.swing;

import sun.reflect.misc.ReflectUtil;
import sun.swing.SwingUtilities2;
import sun.swing.UIAction;

Expand Down Expand Up @@ -2033,7 +2032,6 @@ static void appContextRemove(Object key) {


static Class<?> loadSystemClass(String className) throws ClassNotFoundException {
ReflectUtil.checkPackageAccess(className);
return Class.forName(className, true, Thread.currentThread().
getContextClassLoader());
}
Expand Down
3 changes: 0 additions & 3 deletions src/java.desktop/share/classes/javax/swing/UIDefaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import java.beans.PropertyChangeListener;

import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;
import sun.swing.SwingAccessor;
import sun.swing.SwingUtilities2;

Expand Down Expand Up @@ -702,7 +701,6 @@ public Dimension getDimension(Object key, Locale l) {
try {
String className = (String)get(uiClassID);
if (className != null) {
ReflectUtil.checkPackageAccess(className);

Class<?> cls = (Class)get(className);
if (cls == null) {
Expand Down Expand Up @@ -1142,7 +1140,6 @@ public Object createValue(final UIDefaults table) {
cl = ClassLoader.getSystemClassLoader();
}
}
ReflectUtil.checkPackageAccess(className);
c = Class.forName(className, true, (ClassLoader)cl);
SwingUtilities2.checkAccess(c.getModifiers());
if (methodName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import java.lang.reflect.Array;
import java.util.EventListener;

import sun.reflect.misc.ReflectUtil;

/**
* A class that holds a list of EventListeners. A single instance
* can be used to hold all listeners (of all types) for the instance
Expand Down Expand Up @@ -303,7 +301,6 @@ private void readObject(ObjectInputStream s)
ClassLoader cl = Thread.currentThread().getContextClassLoader();
EventListener l = (EventListener)s.readObject();
String name = (String) listenerTypeOrNull;
ReflectUtil.checkPackageAccess(name);
@SuppressWarnings("unchecked")
Class<EventListener> tmp = (Class<EventListener>)Class.forName(name, true, cl);
add(tmp, l);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import org.xml.sax.helpers.DefaultHandler;

import com.sun.beans.decoder.DocumentHandler;
import sun.reflect.misc.ReflectUtil;

class SynthParser extends DefaultHandler {
//
Expand Down Expand Up @@ -646,7 +645,7 @@ else if (key.equals(ATTRIBUTE_TYPE)) {
}
else {
try {
typeClass = ReflectUtil.forName(typeName.substring(
typeClass = Class.forName(typeName.substring(
0, classIndex));
} catch (ClassNotFoundException cnfe) {
throw new SAXException("Unknown class: " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package javax.swing.text;

import sun.reflect.misc.ReflectUtil;
import sun.swing.SwingUtilities2;

import java.io.Serializable;
Expand Down Expand Up @@ -248,7 +247,6 @@ public Object stringToValue(String string) throws ParseException {
Constructor<?> cons;

try {
ReflectUtil.checkPackageAccess(vc);
SwingUtilities2.checkAccess(vc.getModifiers());
cons = vc.getConstructor(new Class<?>[]{String.class});

Expand Down
Loading

1 comment on commit 7be94d0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.