diff --git a/src/main/java/net/flintmc/launcher/classloading/RootClassLoader.java b/src/main/java/net/flintmc/launcher/classloading/RootClassLoader.java index c358319..bf378e1 100644 --- a/src/main/java/net/flintmc/launcher/classloading/RootClassLoader.java +++ b/src/main/java/net/flintmc/launcher/classloading/RootClassLoader.java @@ -51,6 +51,8 @@ */ public class RootClassLoader extends URLClassLoader implements CommonClassLoader { + private static final Logger LOGGER = LogManager.getLogger(RootClassLoader.class); + static { ClassLoader.registerAsParallelCapable(); } @@ -71,7 +73,7 @@ public class RootClassLoader extends URLClassLoader implements CommonClassLoader * @param urls The new class path of this class loader */ public RootClassLoader(URL[] urls) { - super(urls, null); + super(urls, getPlatformClassloader()); this.currentlyLoading = new HashSet<>(); this.plugins = new HashSet<>(); this.children = new ArrayList<>(); @@ -91,6 +93,26 @@ public RootClassLoader(URL[] urls) { excludeFromModification("net.flintmc.launcher."); } + /** + * Retrieves the classloader from the platform. + * + * @return The platform classloader. + */ + private static ClassLoader getPlatformClassloader() { + String javaVersionProperty = System.getProperty("java.version"); + + if (!javaVersionProperty.startsWith("1.")) { + try { + return (ClassLoader) ClassLoader.class + .getDeclaredMethod("getPlatformClassLoader") + .invoke(null); + } catch (Throwable ignored) { + LOGGER.warn("No platform classloader found: {}", javaVersionProperty); + } + } + return null; + } + public void addModifiedClass(String name, byte[] byteCode) { this.modifiedClasses.put(name, byteCode); } @@ -142,7 +164,7 @@ public void excludeFromModification(String... names) { */ @Override public Class findClass(String name) throws ClassNotFoundException { - return findClass(name, null); + return findClass(name, (ChildClassLoader) null); } /** @@ -274,7 +296,16 @@ public Class findClass(String name, ChildClassLoader preferredLoader) */ @Override public URL findResource(String name) { - return findResource(name, true); + return super.findResource(name); + // TODO: 5/18/2021 + // The findResource(String, boolean) method slows down the startup + // by 10-20 seconds on the Windows operating system. + // + // I think we still need a better solution for this, + // but since there are currently no launcher plugins that could redirect the resource, + // the implementation is fine. + // + // return findResource(name, true); } /**