Skip to content

Commit

Permalink
Suppress asm library bundled with the MC server jar (24w33a) (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfPlayer1 authored Aug 26, 2024
1 parent a2c5248 commit c7f1b65
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@

package net.fabricmc.loader.impl.game.minecraft;

import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.util.concurrent.CompletableFuture;

public final class BundlerClassPathCapture {
Expand All @@ -26,9 +29,42 @@ public final class BundlerClassPathCapture {
public static void main(String[] args) { // invoked by the bundler on a thread
try {
URLClassLoader cl = (URLClassLoader) Thread.currentThread().getContextClassLoader();
FUTURE.complete(cl.getURLs());
URL[] urls = cl.getURLs();

// suppress asm library since it conflicts with Loader's, needed for MC 24w33a

URL asmUrl = cl.findResource("org/objectweb/asm/ClassReader.class");

if (asmUrl != null && (asmUrl = getJarUrl(asmUrl)) != null) {
for (int i = 0; i < urls.length; i++) {
if (urls[i].equals(asmUrl)) {
URL[] newUrls = new URL[urls.length - 1];
System.arraycopy(urls, 0, newUrls, 0, i);
System.arraycopy(urls, i + 1, newUrls, i, urls.length - i - 1);
urls = newUrls;
break;
}
}
}

FUTURE.complete(urls);
} catch (Throwable t) {
FUTURE.completeExceptionally(t);
}
}

/**
* Transform jar:file url to its outer file url.
*
* <p>jar:file:/path/to.jar!/pkg/Cls.class -> file:/path/to.jar
*/
private static URL getJarUrl(URL url) throws IOException {
URLConnection connection = url.openConnection();

if (connection instanceof JarURLConnection) {
return ((JarURLConnection) connection).getJarFileURL();
}

return null;
}
}

0 comments on commit c7f1b65

Please sign in to comment.