Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed EDT Classloading issues after EDT shutdown. #679

Merged
merged 12 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,62 @@
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) {
Assert.requireNonNull(loader, "loader");
this.classLoader = loader;
hendrikebbers marked this conversation as resolved.
Show resolved Hide resolved
}

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) {
sclassen marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}
}