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
--- a/jdk/src/share/classes/java/awt/GraphicsEnvironment.java Mon Jul 13 09:37:50 2009 -0700
+++ b/jdk/src/share/classes/java/awt/GraphicsEnvironment.java Wed Jul 22 15:52:41 2009 +0200
@@ -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,35 +75,53 @@
*/
public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment() {
if (localEnv == null) {
- String nm = (String) java.security.AccessController.doPrivileged
- (new sun.security.action.GetPropertyAction
- ("java.awt.graphicsenv", null));
-
- try {
-// long t0 = System.currentTimeMillis();
- 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);
- }
+ 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();
+ 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 ge;
+ }
+
+ /**
* Tests whether or not a display, keyboard, and mouse can be
* supported in this environment. If this method returns true,
* a HeadlessException is thrown from areas of the Toolkit