From bd6ba6774576ecf8044bc7f00e2a283e5127e939 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Mon, 7 Feb 2022 05:20:05 +0700 Subject: [PATCH] Bug fix: Arc DNS injector breaks on Java 16+ This is caused by a missing function in our class loader. Error: System class loader does not define the appendToClassPathForInstrumentation method Unable to add /Applications/PojavLauncher.app/libs/arc_dns_injector.jar to system class path - the system class loader does not define the appendToClassPathForInstrumentation method or the method failed FATAL ERROR in native method: processing of -javaagent failed, appending to system class path failed --- .../net/kdt/pojavlaunch/PojavClassLoader.java | 29 ++++++++++++++++++- Natives/JavaLauncher.m | 4 +++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/PojavClassLoader.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/PojavClassLoader.java index 386b4356..c39679ab 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/PojavClassLoader.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/PojavClassLoader.java @@ -1,6 +1,7 @@ package net.kdt.pojavlaunch; import java.io.File; +import java.io.IOException; import java.net.*; /** @@ -13,7 +14,7 @@ public class PojavClassLoader extends URLClassLoader { public PojavClassLoader(ClassLoader parent) { super(new URL[0], parent); } - + @Override public void addURL(URL url) { super.addURL(url); @@ -23,4 +24,30 @@ public class PojavClassLoader extends URLClassLoader { e.printStackTrace(); } } + + static URL getFileURL(File file) { + try { + file = file.getCanonicalFile(); + } catch (IOException e) {} + + try { + return file.toURL(); + } catch (MalformedURLException e) { + // Should never happen since we specify the protocol... + throw new InternalError(e); + } + } + + /** + * This class loader supports dynamic additions to the class path + * at runtime. + * + * @see java.lang.instrument.Instrumentation#appendToSystemClassPathSearch + */ + private void appendToClassPathForInstrumentation(String path) { + assert(Thread.holdsLock(this)); + + // addURL is a no-op if path already contains the URL + super.addURL(getFileURL(new File(path))); + } } \ No newline at end of file diff --git a/Natives/JavaLauncher.m b/Natives/JavaLauncher.m index 474711a1..50a8ea1c 100644 --- a/Natives/JavaLauncher.m +++ b/Natives/JavaLauncher.m @@ -674,7 +674,11 @@ int launchJVM(int argc, char *argv[]) { } margv[margc++] = cacio_classpath; } + } else if (!started) { + // Opens to ARC DNS + margv[margc++] = "--add-opens=java.base/java.net=ALL-UNNAMED"; } + if (!started) { init_loadCustomJvmFlags(); }