changeset 20803:140bc93ee613

8012277: Improve AWT DataFlavor Reviewed-by: art, skoivu
author malenkov
date Fri, 31 May 2013 21:25:42 +0400
parents 758273542f3d
children 18285d130365
files jdk/src/share/classes/java/awt/datatransfer/DataFlavor.java
diffstat 1 files changed, 31 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/share/classes/java/awt/datatransfer/DataFlavor.java	Mon May 20 19:49:20 2013 +0400
+++ b/jdk/src/share/classes/java/awt/datatransfer/DataFlavor.java	Fri May 31 21:25:42 2013 +0400
@@ -30,6 +30,9 @@
 import java.util.*;
 
 import sun.awt.datatransfer.DataTransferer;
+import sun.reflect.misc.ReflectUtil;
+
+import static sun.security.util.SecurityConstants.GET_CLASSLOADER_PERMISSION;
 
 /**
  * A {@code DataFlavor} provides meta information about data. {@code DataFlavor}
@@ -116,26 +119,36 @@
                                                    ClassLoader fallback)
         throws ClassNotFoundException
     {
-        ClassLoader systemClassLoader = (ClassLoader)
-            java.security.AccessController.doPrivileged(
-                new java.security.PrivilegedAction() {
-                    public Object run() {
-                        ClassLoader cl = Thread.currentThread().
-                            getContextClassLoader();
-                        return (cl != null)
-                            ? cl
-                            : ClassLoader.getSystemClassLoader();
+        ReflectUtil.checkPackageAccess(className);
+        try {
+            SecurityManager sm = System.getSecurityManager();
+            if (sm != null) {
+                sm.checkPermission(GET_CLASSLOADER_PERMISSION);
+            }
+            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);
                     }
-                    });
-
-        try {
-            return Class.forName(className, true, systemClassLoader);
-        } catch (ClassNotFoundException e2) {
-            if (fallback != null) {
-                return Class.forName(className, true, fallback);
-            } else {
-                throw new ClassNotFoundException(className);
+                    catch (ClassNotFoundException e) {
+                        // fallback to user's class loader
+                    }
+                }
             }
+        } catch (SecurityException exception) {
+            // ignore secured class loaders
+        }
+        if (fallback != null) {
+            return Class.forName(className, true, fallback);
+        } else {
+            throw new ClassNotFoundException(className);
         }
     }