Skip to content

Bug in directory exclusion logic in ClasspathResolver. #311

@seadbrane

Description

@seadbrane

There is an issue in 0.9.14 (at least with some classloaders) in ClasspathResolver line 43, where getResource returns a non null URL for non-existent paths in the JAR which results in assuming it is a directory, when it is actually a valid classpath template resource.

 43                } else if (ccl.getResource(normalizeResourceName + "/") != null) {
 44                     // This is a directory
 45                     return null;
 46                 }'

Proposed fix:

-                } else if (ccl.getResource(normalizeResourceName + "/") != null) {
-                    // This is a directory
-                    return null;
+                }
+                // Use JarURLConnection to accurately check if this is a directory in the jar
+                try {
+                    JarURLConnection jarConn = (JarURLConnection) resource.openConnection();
+                    JarEntry entry = jarConn.getJarEntry();
+                    if (entry != null && entry.isDirectory()) {
+                        return null;
+                    }
+                } catch (IOException e) {
+                    // If we can't check, assume it's a file and proceed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions