Skip to content

Commit

Permalink
Merge pull request #679 from Gr33nbl00d/master
Browse files Browse the repository at this point in the history
Fixed EDT Classloading issues after EDT shutdown.
  • Loading branch information
hendrikebbers authored Aug 11, 2020
2 parents 6a72559 + f434dd0 commit a5799db
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/src/main/java/net/sourceforge/jnlp/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
import net.adoptopenjdk.icedteaweb.resources.UpdatePolicy;
import net.adoptopenjdk.icedteaweb.ui.swing.SwingUtils;
import net.sourceforge.jnlp.config.DeploymentConfiguration;
import net.sourceforge.jnlp.runtime.AppContextFactory;
import net.sourceforge.jnlp.runtime.AppletInstance;
import net.sourceforge.jnlp.runtime.ApplicationInstance;
import net.sourceforge.jnlp.runtime.classloader.JNLPClassLoader;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
import net.sourceforge.jnlp.runtime.classloader.DelegatingClassLoader;
import net.sourceforge.jnlp.runtime.classloader.JNLPClassLoader;
import net.sourceforge.jnlp.services.InstanceExistsException;
import net.sourceforge.jnlp.services.ServiceUtil;
import sun.awt.SunToolkit;

import javax.swing.text.html.parser.ParserDelegator;
import java.applet.Applet;
Expand Down Expand Up @@ -436,6 +437,9 @@ private void setContextClassLoaderForAllThreads(ThreadGroup tg, ClassLoader clas
}
}

//inject classloader into edt delegating classloader
DelegatingClassLoader.getInstance().setClassLoader(classLoader);

}

/**
Expand Down Expand Up @@ -643,8 +647,7 @@ public void run() {
try {
// Do not create new AppContext if we're using NetX and icedteaplugin.
// The plugin needs an AppContext too, but it has to be created earlier.
SunToolkit.createNewAppContext();

AppContextFactory.createNewAppContext();
doPerApplicationAppContextHacks();

if (file.isApplication()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.sourceforge.jnlp.runtime;

import net.sourceforge.jnlp.runtime.classloader.DelegatingClassLoader;
import sun.awt.SunToolkit;

public class AppContextFactory {
public static void createNewAppContext() {
//set temporary classloader for EventQueue initialization
//already a call to AppContext.getAppContext(...) initializes the EventQueue.class
ClassLoader originalLoader = Thread.currentThread().getContextClassLoader();
try {
DelegatingClassLoader delegatingLoader = DelegatingClassLoader.getInstance();
delegatingLoader.setClassLoader(originalLoader);

Thread.currentThread().setContextClassLoader(delegatingLoader);
SunToolkit.createNewAppContext();
}finally {
//restore original classloader
Thread.currentThread().setContextClassLoader(originalLoader);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.sourceforge.jnlp.runtime.classloader;

import net.adoptopenjdk.icedteaweb.Assert;

import java.net.URL;
import java.util.Objects;

public class DelegatingClassLoader extends ClassLoader {
public static final DelegatingClassLoader instance = new DelegatingClassLoader(Thread.currentThread().getContextClassLoader());
private ClassLoader classLoader;

public static DelegatingClassLoader getInstance() {
return instance;
}

private DelegatingClassLoader(ClassLoader loader) {
super(Assert.requireNonNull(loader, "loader"));
this.classLoader = loader;
}

public void setClassLoader(ClassLoader loader) {
this.classLoader = Assert.requireNonNull(loader, "loader");
}

protected Class findClass(String name) throws ClassNotFoundException {
return this.classLoader.loadClass(name);
}

protected URL findResource(String name) {
return this.classLoader.getResource(name);
}

public int hashCode() {
int result = 1;
result = 31 * result + (this.classLoader == null ? 0 : this.classLoader.hashCode());
result = 31 * result + (this.getParent() == null ? 0 : this.getParent().hashCode());
return result;
}

public boolean equals(Object obj) {
if (this == obj) {
return true;
}
else if (obj == null) {
return false;
}
else if (this.getClass() != obj.getClass()) {
return false;
}
else {
DelegatingClassLoader other = (DelegatingClassLoader) obj;
if(!Objects.equals(this.classLoader,other.classLoader)) {
return false;
}
if(!Objects.equals(this.getParent(),other.getParent())) {
return false;
}
return true;
}
}
}

0 comments on commit a5799db

Please sign in to comment.