Skip to content

ClassGraph doesn't scan Application ClassLoader when provided as override on JDK11 #411

@chrisr3

Description

@chrisr3

This problem looks like an edge-case of #382 . We are using ClassGraph 4.8.58, but the problem still exists with 4.8.65.

Basically, we are configuring ClassGraph with

ClassGraph().overrideClassLoaders(classloader)
    .ignoreParentClassLoaders()
    .enableClassInfo()
    .scan()

The classloader parameter is usually expected to be an instance of URLClassLoader but in some circumstances it may be the application classloader, and Java 8 is fine with this. However, ClassGraph doesn't find anything inside the application classloader on Java 11! The fix from #382 does enable module scanning, but the "Module Finder" still doesn't find any modules to scan.

We are currently working around this using:

ClassGraph().apply {
    if (classloader !== ClassLoader.getSystemClassLoader()) {
        overrideClassLoaders(classloader)
    }
}.ignoreParentClassLoaders()
 .enableClassInfo()
 .scan()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions