Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

classgraph-4.8.130 introduces NPE when scanning with overridden classloader #639

Closed
limbic-derek opened this issue Jan 23, 2022 · 3 comments

Comments

@limbic-derek
Copy link

I tracked down this regression to this particular release.

Here's what I'm doing:

  private void getClassInfo(Class<?> clazz) {
    try (var results =
        classGraph
            .acceptClasses(clazz.getName())
            .overrideClassLoaders(clazz.getClassLoader())
            .scan()) {
      var classInfo = results.getClassInfo(clazz.getName());
      // do stuff w/ classInfo except its null here in 4.8.130
    }
  }

  public final class SomeClass {
  }

public static test() {
  getClassInfo(SomeClass.class);
}

Prior to release 4.8.130, I would get what I expected (ClassInfo for SomeClass), by upgrading to this version, I get a null.
Any thoughts on this? I also verified this is still broken w/ the latest release for me.

@lukehutch
Copy link
Member

Sorry for the delay, I have been busy traveling for the last 3 weeks.

I figured out what is happening here. You are overriding the classloader with an AppClassLoader instance, the module-oriented classloader for JDK 9+. This classloader supports the traditional classpath, but it doesn't make the classpath available via any public methods or fields. If you override the classloader, the classpath is ignored (this is the change that was introduced in 4.8.130, I believe) -- because normally if you're specifying a classloader to scan, you want to ignore everything else.

I think the right fix here is to check if an override classloader is AppClassLoader, and if so, add the contents of the system property java.class.path to the list of things to be scanned.

@lukehutch
Copy link
Member

OK, this is fixed, and will be in the next release (once I catch up with fixing a few other bugs). Thank you for your report!

@lukehutch
Copy link
Member

Released in 4.8.139. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants