Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LoaderUtil saying there are duplicate classpath entries if there are in fact none. #979

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/main/java/net/fabricmc/loader/impl/util/LoaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public final class LoaderUtil {
private static final ConcurrentMap<Path, Path> 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");
Expand Down Expand Up @@ -66,17 +68,21 @@ public static void verifyNotInTargetCl(Class<?> cls) {

public static void verifyClasspath() {
try {
List<URL> resources = Collections.list(LoaderUtil.class.getClassLoader().getResources("net/fabricmc/loader/api/FabricLoader.class"));
List<URL> 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);
Expand Down
Loading