From d20e86295640826841836655aa97db308b69efa3 Mon Sep 17 00:00:00 2001 From: Gamebuster19901 Date: Wed, 18 Sep 2024 20:52:52 -0400 Subject: [PATCH] Fix LoaderUtil saying there are duplicate classpath entries if there are none. Also futureproofs the checks just in case the class names are changed. --- .../net/fabricmc/loader/impl/util/LoaderUtil.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/fabricmc/loader/impl/util/LoaderUtil.java b/src/main/java/net/fabricmc/loader/impl/util/LoaderUtil.java index 82f9f8235..6c7f6bf6c 100644 --- a/src/main/java/net/fabricmc/loader/impl/util/LoaderUtil.java +++ b/src/main/java/net/fabricmc/loader/impl/util/LoaderUtil.java @@ -30,6 +30,8 @@ public final class LoaderUtil { private static final ConcurrentMap pathNormalizationCache = new ConcurrentHashMap<>(); + private static final String FABRIC_LOADER_CLASS = "net/fabricmc/loader/api/FabricLoader.class"; + private static final String ASM_CLASS = "org/objectweb/asm/ClassReader.class"; public static String getClassFileName(String className) { return className.replace('.', '/').concat(".class"); @@ -66,17 +68,21 @@ public static void verifyNotInTargetCl(Class cls) { public static void verifyClasspath() { try { - List resources = Collections.list(LoaderUtil.class.getClassLoader().getResources("net/fabricmc/loader/api/FabricLoader.class")); + List resources = Collections.list(LoaderUtil.class.getClassLoader().getResources(FABRIC_LOADER_CLASS)); - if (resources.size() != 1) { + if (resources.size() > 1) { // This usually happens when fabric loader has been added to the classpath more than once. throw new IllegalStateException("duplicate fabric loader classes found on classpath: " + resources.stream().map(URL::toString).collect(Collectors.joining(", "))); + } else if (resources.size() < 1) { + throw new AssertionError(FABRIC_LOADER_CLASS + " not detected on the classpath?! (perhaps it was renamed?)"); } - resources = Collections.list(LoaderUtil.class.getClassLoader().getResources("org/objectweb/asm/ClassReader.class")); + resources = Collections.list(LoaderUtil.class.getClassLoader().getResources(ASM_CLASS)); - if (resources.size() != 1) { + if (resources.size() > 1) { throw new IllegalStateException("duplicate ASM classes found on classpath: " + resources.stream().map(URL::toString).collect(Collectors.joining(", "))); + } else if (resources.size() < 1) { + throw new IllegalStateException("ASM not detected on the classpath (or perhaps " + ASM_CLASS + " was renamed?)"); } } catch (IOException e) { throw new UncheckedIOException("Failed to get resources", e);