spullara / spullara/mustache.java

Bug in directory exclusion logic in ClasspathResolver.

Open
#311 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
2k
Forks
281
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in ClasspathResolver around line 43 and inspect how getResource handles classpath template resources and directory exclusions. Verify the behavior with the relevant classloader, ensuring valid non-directory resources are not excluded while actual JAR directories still are; the issue does not name a test file to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.