question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

overrideClassLoaders(AppClassLoader) not no-op with Java 11

See original GitHub issue

This might just be a semantic issue, but it is an obvious change in behaviour vs running on Java 8.

We are executing ClassGraph as follows:

ClassGraph().overrideClassLoaders(classLoader)
    .ignoreParentClassLoaders()
    .enableClassinfo()
    .scan()

The classLoader is allowed to be AppClassLoader, and this isn’t a problem on Java 8. However, it does cause problems on Java 11. I have tested ClassGraph 4.8.58, 4.8.65 and 4.8.67, and none of them finds any nonSystemModuleRefs, although 4.8.67 does at least find the systemModuleRefs. (To be precise, ClassGraph does find lots of “unnamed modules” on the call-stack, but rejects them all because layer == null.)

We are working around this by doing the following:

ClassGraph().apply {
    if (classLoader !== ClassLoader.getSystemClassLoader()) {
        overrideClassLoaders(classLoader)
    }
}.ignoreParentClassLoaders()
 .enableClassinfo()
 .scan()

This works because it allows ClasspathFinder to consult the java.class.path system property and so populate the classpathOrder field instead. And to be clear, these are the jars we want to be scanning. We have no need to scan the systemModuleRefs here.

See #382 and #411.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
GedMarccommented, Apr 6, 2020

@lukehutch Hey Luke, we pushed .68 into our production environment today on JLink JDK 14 😃

Still perfect! And still one of the only libraries that is keeping up with the pace of the new 6 month releases!

1reaction
chrisr3commented, Apr 4, 2020

Thanks, my tests pass with the new changes. I was slightly concerned that

ClasGraph().apply {
    if (classLoader !== ClassLoader.getSystemClassLoader()) {
        overrideClassLoaders(classLoader)
    }
}

was adding an extra 20 elements to the order than

ClasGraph().overrideClassLoaders(classLoader)

does when classLoader is AppClassLoader, but then I realised that these 20 jars were all Gradle and so their exclusion was a Good Thing ™️!

I like it! I like it a lot… 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java 9, compatability issue with ClassLoader ...
Caused by: java.lang.ClassCastException: jdk.internal.loader.ClassLoaders$AppClassLoader (in module: java.base) cannot be cast to java.net.
Read more >
ClassLoader (Java SE 12 & JDK 12 ) - Oracle Help Center
This method should be overridden by class loader implementations that follow the delegation model for loading classes, and will be invoked by the...
Read more >
ClassLoader in Java - Javatpoint
Delegation principle: It forwards the request for class loading to parent class loader. It only loads the class if the parent does not...
Read more >
The Classpath is a Lie - Lambda Island
It does give you a way to override the classloader that Clojure uses, by giving that var a root binding. This is something...
Read more >
Transition from Java 8 to Java 11 - Azure - Microsoft Learn
In Java 11, the boot class loader only loads core modules. If you create a class loader with a null parent, it may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found