🐛 Allow Class Loader to Enumerate Directory Entries#1049
Merged
ArneBab merged 1 commit intoApr 6, 2025
Conversation
JAR (ZIP) files are technically not required to have directory entries; it is absolutely fine for a JAR file to only have a META-INF/MANIFEST.MF entry, without a corresponding META-INF directory entry. If a JAR file does have separate entries for directories, though, the getResource() and getResources() methods are expected to return URLs for these entries. Our JarClassLoader did not do that. The problem occured when I was working with Flyway and its classpath scanning: it refused to locate the directory in the classpath that the migration scripts were stored in. After much debugging it was found that the name of the directory is handed in to getResources() without a trailing slash, but the JarClassLoader uses the ZipEntry.getName() method to get the name of the current entry, and that method will return a name ending with “/” if the entry is a directory. The fix is to check for a name with an appended slash as well.
ArneBab
approved these changes
Apr 6, 2025
ArneBab
left a comment
Contributor
There was a problem hiding this comment.
That’s a good catch! 👍
Thank you for the fix!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JAR (ZIP) files are technically not required to have directory entries; it is absolutely fine for a JAR file to only have a
META-INF/MANIFEST.MFentry, without a correspondingMETA-INFdirectory entry.If a JAR file does have separate entries for directories, though, the
getResource()andgetResources()methods are expected to return URLs for these entries. OurJarClassLoaderdid not do that.The problem occured when I was working with Flyway and its classpath scanning: it refused to locate the directory in the classpath that the migration scripts were stored in. After much debugging it was found that the name of the directory is handed in to
getResources()without a trailing slash, but theJarClassLoaderuses theZipEntry.getName()method to get the name of the current entry, and that method will return a name ending with “/” if the entry is a directory.The fix is to check for a name with an appended slash as well.