Files
PojavLauncher_iOS/JavaApp/src/main/java/net/kdt/pojavlaunch/PojavClassLoader.java
T
Duy Tran Khanh bd6ba67745 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
2022-02-07 05:20:05 +07:00

53 lines
1.5 KiB
Java

package net.kdt.pojavlaunch;
import java.io.File;
import java.io.IOException;
import java.net.*;
/**
* This class loader is used as system class loader
* as a workaround to modded libraries for Java 8
* compatibility that safety casting to URLClassLoader:
* ((URLClassLoader) ClassLoader.getSystemClassLoader())
*/
public class PojavClassLoader extends URLClassLoader {
public PojavClassLoader(ClassLoader parent) {
super(new URL[0], parent);
}
@Override
public void addURL(URL url) {
super.addURL(url);
try {
System.setProperty("java.class.path", System.getProperty("java.class.path") + ":" + new File(url.toURI()).getAbsolutePath());
} catch (URISyntaxException e) {
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)));
}
}