6857358: Two testcases are failing in jdk7 b64 pit build with java.security.AccessControlException
Try to load GraphicsEnvironment with bootclassloader first, only then try app classloader. Reviewed-by: prr, tdv, igor
This commit is contained in:
parent
08c5418a0b
commit
1b3374bcce
@ -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,15 +75,35 @@ 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 {
|
||||
// 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();
|
||||
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()) {
|
||||
@ -96,9 +118,7 @@ public abstract class GraphicsEnvironment {
|
||||
throw new Error ("Could not access Graphics Environment: "
|
||||
+ nm);
|
||||
}
|
||||
}
|
||||
|
||||
return localEnv;
|
||||
return ge;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user