From 99070658fd09ee3d1835f814c939d62e249c5704 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Fri, 15 Nov 2024 04:51:55 +0000 Subject: [PATCH] 8344065: Remove SecurityManager uses from the java.datatransfer module Reviewed-by: serb --- src/java.base/share/classes/module-info.java | 1 - .../java/awt/datatransfer/DataFlavor.java | 37 +++++++------------ .../awt/datatransfer/SystemFlavorMap.java | 8 +--- 3 files changed, 14 insertions(+), 32 deletions(-) diff --git a/src/java.base/share/classes/module-info.java b/src/java.base/share/classes/module-info.java index 85ccb2192fb..d683d837a09 100644 --- a/src/java.base/share/classes/module-info.java +++ b/src/java.base/share/classes/module-info.java @@ -313,7 +313,6 @@ module java.base { java.desktop; exports sun.reflect.misc to java.desktop, - java.datatransfer, java.management, java.management.rmi, java.rmi, diff --git a/src/java.datatransfer/share/classes/java/awt/datatransfer/DataFlavor.java b/src/java.datatransfer/share/classes/java/awt/datatransfer/DataFlavor.java index 757c4f99f45..f228f1a4da1 100644 --- a/src/java.datatransfer/share/classes/java/awt/datatransfer/DataFlavor.java +++ b/src/java.datatransfer/share/classes/java/awt/datatransfer/DataFlavor.java @@ -45,7 +45,6 @@ import java.util.Collections; import java.util.Objects; import sun.datatransfer.DataFlavorUtil; -import sun.reflect.misc.ReflectUtil; /** * A {@code DataFlavor} provides meta information about data. {@code DataFlavor} @@ -131,32 +130,22 @@ public class DataFlavor implements Externalizable, Cloneable { 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); } diff --git a/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java b/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java index 6b2dc14c05f..deea133b734 100644 --- a/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java +++ b/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java @@ -30,8 +30,6 @@ import java.io.IOException; 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; @@ -202,12 +200,8 @@ public final class SystemFlavorMap implements FlavorMap, FlavorTable { } isMapInitialized = true; - @SuppressWarnings("removal") - InputStream is = AccessController.doPrivileged( - (PrivilegedAction) () -> { - 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"); }