Skip to content

Commit

Permalink
8344065: Remove SecurityManager uses from the java.datatransfer module
Browse files Browse the repository at this point in the history
Reviewed-by: serb
  • Loading branch information
prrace committed Nov 15, 2024
1 parent db56266 commit 9907065
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
1 change: 0 additions & 1 deletion src/java.base/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@
java.desktop;
exports sun.reflect.misc to
java.desktop,
java.datatransfer,
java.management,
java.management.rmi,
java.rmi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.util.Objects;

import sun.datatransfer.DataFlavorUtil;
import sun.reflect.misc.ReflectUtil;

/**
* A {@code DataFlavor} provides meta information about data. {@code DataFlavor}
Expand Down Expand Up @@ -131,32 +130,22 @@ protected static final Class<?> tryToLoadClass(String className,
ClassLoader fallback)
throws ClassNotFoundException
{
ReflectUtil.checkPackageAccess(className);
ClassLoader loader = ClassLoader.getSystemClassLoader();
try {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("getClassLoader"));
}
ClassLoader loader = ClassLoader.getSystemClassLoader();
try {
// bootstrap class loader and system class loader if present
return Class.forName(className, true, loader);
}
catch (ClassNotFoundException exception) {
// thread context class loader if and only if present
loader = Thread.currentThread().getContextClassLoader();
if (loader != null) {
try {
return Class.forName(className, true, loader);
}
catch (ClassNotFoundException e) {
// fallback to user's class loader
}
// bootstrap class loader and system class loader if present
return Class.forName(className, true, loader);
}
catch (ClassNotFoundException exception) {
// thread context class loader if and only if present
loader = Thread.currentThread().getContextClassLoader();
if (loader != null) {
try {
return Class.forName(className, true, loader);
}
catch (ClassNotFoundException e) {
// fallback to user's class loader
}
}
} catch (SecurityException exception) {
// ignore secured class loaders
}
return Class.forName(className, true, fallback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.ref.SoftReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -202,12 +200,8 @@ private void initSystemFlavorMap() {
}
isMapInitialized = true;

@SuppressWarnings("removal")
InputStream is = AccessController.doPrivileged(
(PrivilegedAction<InputStream>) () -> {
return SystemFlavorMap.class.getResourceAsStream(
InputStream is = SystemFlavorMap.class.getResourceAsStream(
"/sun/datatransfer/resources/flavormap.properties");
});
if (is == null) {
throw new InternalError("Default flavor mapping not found");
}
Expand Down

0 comments on commit 9907065

Please sign in to comment.