From 1d96b5778bcd0e72974921ec99b2149f2003e4c4 Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Sat, 14 Jan 2023 21:04:58 +0100 Subject: [PATCH] Don't attempt to relaunch ModLaunch when it failed --- .../java/org/spongepowered/mij/SharedModLauncher.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/org/spongepowered/mij/SharedModLauncher.java b/src/main/java/org/spongepowered/mij/SharedModLauncher.java index c5f11cd..516c729 100644 --- a/src/main/java/org/spongepowered/mij/SharedModLauncher.java +++ b/src/main/java/org/spongepowered/mij/SharedModLauncher.java @@ -32,6 +32,7 @@ */ public class SharedModLauncher { private static ClassLoader transformingClassLoader; + private static boolean launcherFailed = false; /** * Returns the shared transforming class loader. @@ -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(); @@ -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);