Skip to content

Commit

Permalink
Verify that ASM is only on the classpath once. (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 authored Aug 15, 2024
1 parent 991d38d commit 633f91a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/main/java/net/fabricmc/loader/impl/launch/knot/Knot.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,6 @@ public static void main(String[] args) {

static {
LoaderUtil.verifyNotInTargetCl(Knot.class);

if (IS_DEVELOPMENT) {
LoaderUtil.verifyClasspath();
}
LoaderUtil.verifyClasspath();
}
}
8 changes: 7 additions & 1 deletion src/main/java/net/fabricmc/loader/impl/util/LoaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ public static void verifyNotInTargetCl(Class<?> cls) {

public static void verifyClasspath() {
try {
final List<URL> resources = Collections.list(LoaderUtil.class.getClassLoader().getResources("net/fabricmc/loader/api/FabricLoader.class"));
List<URL> resources = Collections.list(LoaderUtil.class.getClassLoader().getResources("net/fabricmc/loader/api/FabricLoader.class"));

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(", ")));
}

resources = Collections.list(LoaderUtil.class.getClassLoader().getResources("org/objectweb/asm/ClassReader.class"));

if (resources.size() != 1) {
throw new IllegalStateException("duplicate ASM classes found on classpath: " + resources.stream().map(URL::toString).collect(Collectors.joining(", ")));
}
} catch (IOException e) {
throw new UncheckedIOException("Failed to get resources", e);
}
Expand Down

0 comments on commit 633f91a

Please sign in to comment.