提交 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,28 +119,38 @@ public class DataFlavor implements Externalizable, Cloneable { ...@@ -116,28 +119,38 @@ public class DataFlavor implements Externalizable, Cloneable {
ClassLoader fallback) ClassLoader fallback)
throws ClassNotFoundException throws ClassNotFoundException
{ {
ClassLoader systemClassLoader = (ClassLoader) ReflectUtil.checkPackageAccess(className);
java.security.AccessController.doPrivileged( try {
new java.security.PrivilegedAction() { SecurityManager sm = System.getSecurityManager();
public Object run() { if (sm != null) {
ClassLoader cl = Thread.currentThread(). sm.checkPermission(GET_CLASSLOADER_PERMISSION);
getContextClassLoader(); }
return (cl != null) ClassLoader loader = ClassLoader.getSystemClassLoader();
? cl try {
: ClassLoader.getSystemClassLoader(); // 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 { try {
return Class.forName(className, true, systemClassLoader); return Class.forName(className, true, loader);
} catch (ClassNotFoundException e2) { }
catch (ClassNotFoundException e) {
// fallback to user's class loader
}
}
}
} catch (SecurityException exception) {
// ignore secured class loaders
}
if (fallback != null) { if (fallback != null) {
return Class.forName(className, true, fallback); return Class.forName(className, true, fallback);
} else { } else {
throw new ClassNotFoundException(className); throw new ClassNotFoundException(className);
} }
} }
}
/* /*
* private initializer * private initializer
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册