classgraph: Unable to resolve UNC-based classpath entries
Hello Luke!
I have come across a problem where UNC-based classpath entries are not resolved correctly. I think I’ve boiled it down to this test scenario:
public class Main {
public static void main(String[] args) throws Exception {
String packagesToScan = args[0];
String interfaceClass = args[1];
ScanResult scanResult = new ClassGraph().acceptPackages(packagesToScan)
.ignoreParentClassLoaders()
.overrideClasspath("\\\\192.168.216.1\\workspace\\gemfire\\geode-assembly\\build\\install\\apache-geode\\lib\\spring-shell-1.2.0.RELEASE.jar")
.enableClassInfo()
.enableRealtimeLogging()
.scan(1);
ClassInfoList classInfoList = scanResult.getClassesImplementing(interfaceClass);
classInfoList.forEach(x -> System.out.println(x.getName()));
}
}
When run with these args:
org.springframework.shell org.springframework.shell org.springframework.shell.core.Converter
Produces this log:
Sep 26, 2022 2:09:52 PM nonapi.io.github.classgraph.utils.LogNode flush
INFO: 2022-09-26T14:09:52.636-0700 ClassGraph ClassGraph version 4.8.149
2022-09-26T14:09:52.637-0700 ClassGraph Operating system: Windows 10 10.0 amd64
2022-09-26T14:09:52.637-0700 ClassGraph Java version: 1.8.0_345 / 1.8.0_345-b01 (BellSoft)
2022-09-26T14:09:52.638-0700 ClassGraph Java home: C:\Users\IEUser\.jdks\liberica-1.8.0_345\jre
2022-09-26T14:09:52.648-0700 ClassGraph JRE rt.jar:
2022-09-26T14:09:52.648-0700 ClassGraph -- C:/Users/IEUser/.jdks/liberica-1.8.0_345/jre/lib/rt.jar
2022-09-26T14:09:52.658-0700 ClassGraph ScanSpec:
2022-09-26T14:09:52.658-0700 ClassGraph -- packageAcceptReject: accept: ["org.springframework.shell"]; acceptPrefixes: ["", "/", "org.", "org.springframework.", "org.springframework.shell."]
2022-09-26T14:09:52.658-0700 ClassGraph -- packagePrefixAcceptReject: acceptPrefixes: ["org.springframework.shell."]
2022-09-26T14:09:52.658-0700 ClassGraph -- pathAcceptReject: accept: ["org/springframework/shell/"]; acceptPrefixes: ["", "/", "org/", "org/springframework/", "org/springframework/shell/"]
2022-09-26T14:09:52.658-0700 ClassGraph -- pathPrefixAcceptReject: acceptPrefixes: ["org/springframework/shell/"]
2022-09-26T14:09:52.658-0700 ClassGraph -- classAcceptReject:
2022-09-26T14:09:52.658-0700 ClassGraph -- classfilePathAcceptReject:
2022-09-26T14:09:52.659-0700 ClassGraph -- classPackageAcceptReject:
2022-09-26T14:09:52.659-0700 ClassGraph -- classPackagePathAcceptReject:
2022-09-26T14:09:52.659-0700 ClassGraph -- moduleAcceptReject:
2022-09-26T14:09:52.659-0700 ClassGraph -- jarAcceptReject:
2022-09-26T14:09:52.659-0700 ClassGraph -- classpathElementResourcePathAcceptReject:
2022-09-26T14:09:52.659-0700 ClassGraph -- libOrExtJarAcceptReject:
2022-09-26T14:09:52.660-0700 ClassGraph -- scanJars: true
2022-09-26T14:09:52.660-0700 ClassGraph -- scanNestedJars: true
2022-09-26T14:09:52.660-0700 ClassGraph -- scanDirs: true
2022-09-26T14:09:52.660-0700 ClassGraph -- scanModules: true
2022-09-26T14:09:52.660-0700 ClassGraph -- enableClassInfo: true
2022-09-26T14:09:52.660-0700 ClassGraph -- enableFieldInfo: false
2022-09-26T14:09:52.660-0700 ClassGraph -- enableMethodInfo: false
2022-09-26T14:09:52.660-0700 ClassGraph -- enableAnnotationInfo: false
2022-09-26T14:09:52.660-0700 ClassGraph -- enableStaticFinalFieldConstantInitializerValues: false
2022-09-26T14:09:52.660-0700 ClassGraph -- enableInterClassDependencies: false
2022-09-26T14:09:52.661-0700 ClassGraph -- enableExternalClasses: false
2022-09-26T14:09:52.661-0700 ClassGraph -- enableSystemJarsAndModules: false
2022-09-26T14:09:52.661-0700 ClassGraph -- ignoreClassVisibility: false
2022-09-26T14:09:52.661-0700 ClassGraph -- ignoreFieldVisibility: false
2022-09-26T14:09:52.661-0700 ClassGraph -- ignoreMethodVisibility: false
2022-09-26T14:09:52.661-0700 ClassGraph -- disableRuntimeInvisibleAnnotations: false
2022-09-26T14:09:52.661-0700 ClassGraph -- extendScanningUpwardsToExternalClasses: true
2022-09-26T14:09:52.661-0700 ClassGraph -- allowedURLSchemes: null
2022-09-26T14:09:52.661-0700 ClassGraph -- addedClassLoaders: null
2022-09-26T14:09:52.661-0700 ClassGraph -- overrideClassLoaders: null
2022-09-26T14:09:52.661-0700 ClassGraph -- addedModuleLayers: null
2022-09-26T14:09:52.661-0700 ClassGraph -- overrideModuleLayers: null
2022-09-26T14:09:52.661-0700 ClassGraph -- overrideClasspath: [\\192.168.216.1\workspace\gemfire\geode-assembly\build\install\apache-geode\lib\spring-shell-1.2.0.RELEASE.jar]
2022-09-26T14:09:52.661-0700 ClassGraph -- classpathElementFilters: null
2022-09-26T14:09:52.661-0700 ClassGraph -- initializeLoadedClasses: false
2022-09-26T14:09:52.662-0700 ClassGraph -- removeTemporaryFilesAfterScan: false
2022-09-26T14:09:52.662-0700 ClassGraph -- ignoreParentClassLoaders: true
2022-09-26T14:09:52.662-0700 ClassGraph -- ignoreParentModuleLayers: false
2022-09-26T14:09:52.662-0700 ClassGraph -- modulePathInfo:
2022-09-26T14:09:52.662-0700 ClassGraph -- maxBufferedJarRAMSize: 67108864
2022-09-26T14:09:52.662-0700 ClassGraph -- enableMemoryMapping: false
2022-09-26T14:09:52.662-0700 ClassGraph Number of worker threads: 1
2022-09-26T14:09:52.671-0700 ClassGraph Finding classpath
2022-09-26T14:09:52.672-0700 ClassGraph -- Finding classpath and modules
2022-09-26T14:09:52.693-0700 ClassGraph ---- Overriding classpath with: [\\192.168.216.1\workspace\gemfire\geode-assembly\build\install\apache-geode\lib\spring-shell-1.2.0.RELEASE.jar]
2022-09-26T14:09:52.697-0700 ClassGraph ------ Found classpath element: //192.168.216.1/workspace/gemfire/geode-assembly/build/install/apache-geode/lib/spring-shell-1.2.0.RELEASE.jar
2022-09-26T14:09:52.697-0700 ClassGraph ------ WARNING: when the classpath is overridden, there is no guarantee that the classes found by classpath scanning will be the same as the classes loaded by the context classloader
2022-09-26T14:09:52.700-0700 ClassGraph Opening classpath elements (took 0.107643 sec)
2022-09-26T14:09:52.804-0700 ClassGraph -- Opening classpath element file://192.168.216.1/workspace/gemfire/geode-assembly/build/install/apache-geode/lib/spring-shell-1.2.0.RELEASE.jar
2022-09-26T14:09:52.805-0700 ClassGraph ---- Opening jar: file://192.168.216.1/workspace/gemfire/geode-assembly/build/install/apache-geode/lib/spring-shell-1.2.0.RELEASE.jar
2022-09-26T14:09:52.807-0700 ClassGraph ------ Could not open jarfile file://192.168.216.1/workspace/gemfire/geode-assembly/build/install/apache-geode/lib/spring-shell-1.2.0.RELEASE.jar : java.io.IOException: Could not get logical zipfile file://192.168.216.1/workspace/gemfire/geode-assembly/build/install/apache-geode/lib/spring-shell-1.2.0.RELEASE.jar : java.io.IOException: Could not get PhysicalZipFile for path /192.168.216.1/workspace/gemfire/geode-assembly/build/install/apache-geode/lib/spring-shell-1.2.0.RELEASE.jar : java.io.FileNotFoundException: File does not exist or cannot be read: C:\192.168.216.1\workspace\gemfire\geode-assembly\build\install\apache-geode\lib\spring-shell-1.2.0.RELEASE.jar
2022-09-26T14:09:52.807-0700 ClassGraph Finding nested classpath elements
2022-09-26T14:09:52.807-0700 ClassGraph Final classpath element order:
2022-09-26T14:09:52.808-0700 ClassGraph Scanning classpath elements (took 0.000397 sec)
2022-09-26T14:09:52.808-0700 ClassGraph Masking classfiles (took 0.000017 sec)
2022-09-26T14:09:52.810-0700 ClassGraph Scanning classfiles (took 0.000014 sec)
2022-09-26T14:09:52.810-0700 ClassGraph Linking related classfiles (took 0.000020 sec)
2022-09-26T14:09:52.814-0700 ClassGraph Total time: 0.113 sec
As you’re probably aware, Java can open UNC-based files. If one passes something like file://192.168.216.1/workspace/somefile
to this snippet:
URI uri = new URI(args[0]);
Path path = Paths.get(uri);
The path
ends up pointing to a WindowsPath
object (that looks like \\192.168.216.1\workspace\somefile
) and is able to be opened and read.
Thanks for your time!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (8 by maintainers)
Commits related to this issue
- Convert UNC paths to Path objects (#705) — committed to classgraph/classgraph by lukehutch 2 years ago
- Improve UNC path handling (#705) — committed to classgraph/classgraph by lukehutch 2 years ago
- More UNC path fixes (#705) — committed to classgraph/classgraph by lukehutch 2 years ago
- Another UNC fix (#705) — committed to classgraph/classgraph by lukehutch 2 years ago
- Fix ClassCastException (#705) — committed to classgraph/classgraph by lukehutch 2 years ago
@lukehutch : Thank you for the quick fix!!