/hg/release/icedtea-web-1.4: Added appcontex hack to make sweeth...

jvanek at icedtea.classpath.org jvanek at icedtea.classpath.org
Thu May 2 10:02:32 PDT 2013


changeset eb52d04ba3bd in /hg/release/icedtea-web-1.4
details: http://icedtea.classpath.org/hg/release/icedtea-web-1.4?cmd=changeset;node=eb52d04ba3bd
author: Jiri Vanek <jvanek at redhat.com>
date: Thu May 02 19:02:06 2013 +0200

	Added appcontex hack to make sweethome3d fully working again


diffstat:

 netx/net/sourceforge/jnlp/Launcher.java |  27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diffs (74 lines):

diff -r 0d6213db4fc7 -r eb52d04ba3bd netx/net/sourceforge/jnlp/Launcher.java
--- a/netx/net/sourceforge/jnlp/Launcher.java	Thu May 02 18:44:16 2013 +0200
+++ b/netx/net/sourceforge/jnlp/Launcher.java	Thu May 02 19:02:06 2013 +0200
@@ -20,8 +20,11 @@
 
 import java.applet.Applet;
 import java.awt.Container;
+import java.awt.EventQueue;
 import java.awt.SplashScreen;
+import java.awt.Toolkit;
 import java.io.File;
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.InetAddress;
 import java.net.URL;
@@ -46,6 +49,7 @@
 import net.sourceforge.jnlp.runtime.AppletEnvironment;
 import net.sourceforge.jnlp.splashscreen.SplashUtils;
 
+import sun.awt.AppContext;
 import sun.awt.SunToolkit;
 
 /**
@@ -749,6 +753,7 @@
          AppletInstance appletInstance = null;
          try {
             JNLPClassLoader loader = JNLPClassLoader.getInstance(file, updatePolicy);
+            forceContextClassLoaderHack(loader);
 
             if (enableCodeBase) {
                 loader.enableCodeBase();
@@ -794,6 +799,7 @@
     protected Applet createAppletObject(JNLPFile file, boolean enableCodeBase, Container cont) throws LaunchException {
         try {
             JNLPClassLoader loader = JNLPClassLoader.getInstance(file, updatePolicy);
+            forceContextClassLoaderHack(loader);
 
             if (enableCodeBase) {
                 loader.enableCodeBase();
@@ -817,6 +823,7 @@
     protected ApplicationInstance createApplication(JNLPFile file) throws LaunchException {
         try {
             JNLPClassLoader loader = JNLPClassLoader.getInstance(file, updatePolicy);
+            forceContextClassLoaderHack(loader);
             ThreadGroup group = Thread.currentThread().getThreadGroup();
 
             ApplicationInstance app = new ApplicationInstance(file, group, loader);
@@ -898,6 +905,26 @@
         new ParserDelegator();
     }
 
+    /*
+     * This is necessary to ensure the AppContext context-classloader is correctly set to our JNLPClassLoader.
+     * This is unfortunately necessary until it is possible to create a JNLPClassLoader -before- we create our AppContext.
+     */
+    private void forceContextClassLoaderHack(ClassLoader classLoader) {
+        try {
+            Field appContextClassLoaderField = AppContext.class.getDeclaredField("contextClassLoader");
+            appContextClassLoaderField.setAccessible(true);
+            appContextClassLoaderField.set(AppContext.getAppContext(), classLoader);
+
+            Field eventQueueClassLoaderField = EventQueue.class.getDeclaredField("classLoader");
+            eventQueueClassLoaderField.setAccessible(true);
+            eventQueueClassLoaderField.set(Toolkit.getDefaultToolkit().getSystemEventQueue(), classLoader);
+
+        } catch (Exception e) {
+            System.err.println("Problem occurred while setting the AppContext context-classloader using reflection:");
+            e.printStackTrace();
+        }
+    }
+
        /**
      * This runnable is used to call the appropriate launch method
      * for the application, applet, or installer in its thread group.



More information about the distro-pkg-dev mailing list