-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #679 from Gr33nbl00d/master
Fixed EDT Classloading issues after EDT shutdown.
- Loading branch information
Showing
3 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
core/src/main/java/net/sourceforge/jnlp/runtime/AppContextFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
core/src/main/java/net/sourceforge/jnlp/runtime/classloader/DelegatingClassLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |