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
This commit is contained in:
Duy Tran Khanh committed 2022-02-07 05:20:05 +07:00
1 parent c967c3df7a
commit bd6ba67745
2 files changed
+32 -1

No files matched your search

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