Calling ClassInfo.getResource().open()
after the ScanResult is closed results in a ClassGraph internal NullPointerException.
Reproducer:
package example; import java.io.IOException; import io.github.classgraph.*; class ClassGraphTest { @org.junit.jupiter.api.Test void testClassGraph() throws IOException { final var className = ClassGraphTest.class.getName(); final ClassInfo classInfo; try (ScanResult scanResult = new ClassGraph() // .enableAllInfo() // .acceptClasses(className) // .scan()) { classInfo = scanResult.getClassInfo(className); } try (var res = classInfo.getResource(); var is = res.open()) { // <--- NPE thrown here // do interesting stuff } } }
Exception:
java.lang.NullPointerException: Cannot invoke "java.util.Set.add(Object)" because "this.openSlices" is null at nonapi.io.github.classgraph.fastzipfilereader.NestedJarHandler.markSliceAsOpen(NestedJarHandler.java:517) at nonapi.io.github.classgraph.fileslice.PathSlice.<init>(PathSlice.java:152) at io.github.classgraph.ClasspathElementDir$2.openAndCreateSlice(ClasspathElementDir.java:295) at io.github.classgraph.ClasspathElementDir$2.open(ClasspathElementDir.java:249) at example.ClassGraphTest.testClassGraph(ClassGraphTest.java:25) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Interestingly the same works for JDK built-ins like "java.lang.Integer" and does not throw an NPE
Tested with OpenJDK 17 and classgraph 4.8.176
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4