提交 2e29a076 编写于 作者: R rkennke

6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException

Summary: Try to load GraphicsEnvironment with bootclassloader first, only then try app classloader.
Reviewed-by: prr, tdv, igor
上级 c4bd9837
......@@ -27,9 +27,11 @@
package java.awt;
import java.awt.image.BufferedImage;
import java.security.AccessController;
import java.util.Locale;
import sun.java2d.HeadlessGraphicsEnvironment;
import sun.java2d.SunGraphicsEnvironment;
import sun.security.action.GetPropertyAction;
/**
*
......@@ -73,32 +75,50 @@ public abstract class GraphicsEnvironment {
*/
public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment() {
if (localEnv == null) {
String nm = (String) java.security.AccessController.doPrivileged
(new sun.security.action.GetPropertyAction
("java.awt.graphicsenv", null));
localEnv = createGE();
}
return localEnv;
}
/**
* Creates and returns the GraphicsEnvironment, according to the
* system property 'java.awt.graphicsenv'.
*
* @return the graphics environment
*/
private static GraphicsEnvironment createGE() {
GraphicsEnvironment ge;
String nm = AccessController.doPrivileged(new GetPropertyAction("java.awt.graphicsenv", null));
try {
// long t0 = System.currentTimeMillis();
Class geCls;
try {
// long t0 = System.currentTimeMillis();
// First we try if the bootclassloader finds the requested
// class. This way we can avoid to run in a privileged block.
geCls = Class.forName(nm);
} catch (ClassNotFoundException ex) {
// If the bootclassloader fails, we try again with the
// application classloader.
ClassLoader cl = ClassLoader.getSystemClassLoader();
Class geCls = Class.forName(nm, true, cl);
localEnv = (GraphicsEnvironment)geCls.newInstance();
// long t1 = System.currentTimeMillis();
// System.out.println("GE creation took " + (t1-t0)+ "ms.");
if (isHeadless()) {
localEnv = new HeadlessGraphicsEnvironment(localEnv);
}
} catch (ClassNotFoundException e) {
throw new Error("Could not find class: "+nm);
} catch (InstantiationException e) {
throw new Error("Could not instantiate Graphics Environment: "
+ nm);
} catch (IllegalAccessException e) {
throw new Error ("Could not access Graphics Environment: "
+ nm);
geCls = Class.forName(nm, true, cl);
}
ge = (GraphicsEnvironment) geCls.newInstance();
// long t1 = System.currentTimeMillis();
// System.out.println("GE creation took " + (t1-t0)+ "ms.");
if (isHeadless()) {
localEnv = new HeadlessGraphicsEnvironment(localEnv);
}
} catch (ClassNotFoundException e) {
throw new Error("Could not find class: "+nm);
} catch (InstantiationException e) {
throw new Error("Could not instantiate Graphics Environment: "
+ nm);
} catch (IllegalAccessException e) {
throw new Error ("Could not access Graphics Environment: "
+ nm);
}
return localEnv;
return ge;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册