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);