Skip to content

Commit

Permalink
Attempt to fix logic for override AppClassLoader(#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Mar 5, 2024
1 parent 8bf6dc2 commit 586fecc
Showing 1 changed file with 16 additions and 14 deletions.
Expand Up @@ -136,22 +136,23 @@ public ClasspathFinder(final ScanSpec scanSpec, final ReflectionUtils reflection
// It's not possible to instantiate AppClassLoader or PlatformClassLoader, so if these are
// passed in as override classloaders, they must have been obtained using
// Thread.currentThread().getContextClassLoader() [.getParent()] or similar
if (!scanSpec.enableSystemJarsAndModules) {
if (classpathFinderLog != null && classLoaderClassName
.equals("jdk.internal.loader.ClassLoaders$PlatformClassLoader")) {
classpathFinderLog
.log("overrideClassLoaders() was called with an instance of " + classLoaderClassName
+ ", so enableSystemJarsAndModules() was called automatically");
}
scanSpec.enableSystemJarsAndModules = true;
}
if (classLoaderClassName.equals("jdk.internal.loader.ClassLoaders$AppClassLoader")
|| classLoaderClassName.equals("jdk.internal.loader.ClassLoaders$PlatformClassLoader")) {
if (!scanSpec.enableSystemJarsAndModules) {
if (classpathFinderLog != null) {
classpathFinderLog.log("overrideClassLoaders() was called with an instance of "
+ classLoaderClassName + ", which is a system classloader, so "
+ "enableSystemJarsAndModules() was called automatically");
}
scanSpec.enableSystemJarsAndModules = true;
}
forceScanJavaClassPath = true;
if (classpathFinderLog != null) {
classpathFinderLog.log("overrideClassLoaders() was called with an instance of "
+ classLoaderClassName + ", which is a system classloader, so the "
+ "`java.lang.path` classpath will also be scanned");
classpathFinderLog
.log("overrideClassLoaders() was called with an instance of " + classLoaderClassName
+ ", so the `java.class.path` classpath will also be scanned");
}
forceScanJavaClassPath = true;
}
}
} else {
Expand Down Expand Up @@ -295,8 +296,9 @@ public ClasspathFinder(final ScanSpec scanSpec, final ReflectionUtils reflection
// and the classpath is not overridden, unless only module scanning was enabled, and an unnamed module
// layer was encountered -- in this case, have to forcibly scan java.class.path, since the ModuleLayer
// API doesn't allow for the opening of unnamed modules.
if ((!scanSpec.ignoreParentClassLoaders && (scanSpec.overrideClassLoaders == null || forceScanJavaClassPath)
&& scanSpec.overrideClasspath == null)
if (forceScanJavaClassPath
|| (!scanSpec.ignoreParentClassLoaders && scanSpec.overrideClassLoaders == null
&& scanSpec.overrideClasspath == null)
|| (moduleFinder != null && moduleFinder.forceScanJavaClassPath())) {
final String[] pathElements = JarUtils.smartPathSplit(System.getProperty("java.class.path"), scanSpec);
if (pathElements.length > 0) {
Expand Down

0 comments on commit 586fecc

Please sign in to comment.