Skip to content

Commit

Permalink
Don't attempt to relaunch ModLaunch when it failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Jan 14, 2023
1 parent d7e0d4b commit 1d96b57
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/spongepowered/mij/SharedModLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
public class SharedModLauncher {
private static ClassLoader transformingClassLoader;
private static boolean launcherFailed = false;

/**
* Returns the shared transforming class loader.
Expand All @@ -43,6 +44,11 @@ public class SharedModLauncher {
*/
public static ClassLoader getTransformingClassLoader(String[] launcherArgs) {
if (SharedModLauncher.transformingClassLoader == null) {
if (SharedModLauncher.launcherFailed) {
// Don't attempt to relaunch ModLaunch when it failed
throw new IllegalStateException("ModLauncher has previously failed to launch");
}

final Thread thread = Thread.currentThread();
final ClassLoader originalClassLoader = thread.getContextClassLoader();

Expand All @@ -51,6 +57,9 @@ public static ClassLoader getTransformingClassLoader(String[] launcherArgs) {

// Capture the context class loader set by ModLauncher
SharedModLauncher.transformingClassLoader = thread.getContextClassLoader();
} catch (RuntimeException e) {
SharedModLauncher.launcherFailed = true;
throw e;
} finally {
// Restore the original context class loader to avoid potential issues with classic tests
thread.setContextClassLoader(originalClassLoader);
Expand Down

0 comments on commit 1d96b57

Please sign in to comment.