提交 71e9cefe 编写于 作者: M malenkov

8012277: Improve AWT DataFlavor

Reviewed-by: art, skoivu
上级 ec70c551
...@@ -30,6 +30,9 @@ import java.nio.*; ...@@ -30,6 +30,9 @@ import java.nio.*;
import java.util.*; import java.util.*;
import sun.awt.datatransfer.DataTransferer; 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} * A {@code DataFlavor} provides meta information about data. {@code DataFlavor}
...@@ -116,26 +119,36 @@ public class DataFlavor implements Externalizable, Cloneable { ...@@ -116,26 +119,36 @@ public class DataFlavor implements Externalizable, Cloneable {
ClassLoader fallback) ClassLoader fallback)
throws ClassNotFoundException throws ClassNotFoundException
{ {
ClassLoader systemClassLoader = (ClassLoader) ReflectUtil.checkPackageAccess(className);
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
ClassLoader cl = Thread.currentThread().
getContextClassLoader();
return (cl != null)
? cl
: ClassLoader.getSystemClassLoader();
}
});
try { try {
return Class.forName(className, true, systemClassLoader); SecurityManager sm = System.getSecurityManager();
} catch (ClassNotFoundException e2) { if (sm != null) {
if (fallback != null) { sm.checkPermission(GET_CLASSLOADER_PERMISSION);
return Class.forName(className, true, fallback); }
} else { ClassLoader loader = ClassLoader.getSystemClassLoader();
throw new ClassNotFoundException(className); 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
}
}
}
} catch (SecurityException exception) {
// ignore secured class loaders
}
if (fallback != null) {
return Class.forName(className, true, fallback);
} else {
throw new ClassNotFoundException(className);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册