[OpenJDK 2D-Dev] Load GE via system classloader?

Roman Kennke roman.kennke at aicas.com
Mon May 11 12:06:01 UTC 2009


Hi there,

I'm playing around with Cacio again, and I'd like to load an external GE
(and Toolkit) from the standard classpath. But it turns out to be
impossible, because GE.getLocalGraphicsEnvironment() loads the class by
calling Class.forName(), which uses the classloader that loaded the GE
class, which happens to be the bootclassloader. I _could_ put my stuff
in the bootclasspath, but I don't like that so much, because it means I
have to put my native lib in the JDK lib directory as well. The Toolkit
class already uses the system classloader for loading the toolkit class.
Is there a strong reason to load the GE from the bootclassloader, or
could we apply the attached patch instead?

/Roman

-- 
Dipl.-Inform. (FH) Roman Kennke, Software Engineer, http://kennke.org
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com   * Tel: +49-721-663 968-48
USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt

-------------- next part --------------
diff --git a/src/share/classes/java/awt/GraphicsEnvironment.java b/src/share/classes/java/awt/GraphicsEnvironment.java
--- a/src/share/classes/java/awt/GraphicsEnvironment.java
+++ b/src/share/classes/java/awt/GraphicsEnvironment.java
@@ -79,8 +79,9 @@
 
             try {
 //                      long t0 = System.currentTimeMillis();
-                localEnv =
-                    (GraphicsEnvironment) Class.forName(nm).newInstance();
+                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()) {


More information about the 2d-dev mailing list