Skip to content

🐛 Allow Class Loader to Enumerate Directory Entries#1049

Merged
ArneBab merged 1 commit into
hyphanet:nextfrom
Bombe:fix/jar-class-loader-find-directory-resources
Apr 6, 2025
Merged

🐛 Allow Class Loader to Enumerate Directory Entries#1049
ArneBab merged 1 commit into
hyphanet:nextfrom
Bombe:fix/jar-class-loader-find-directory-resources

Conversation

@Bombe

@Bombe Bombe commented Apr 6, 2025

Copy link
Copy Markdown
Contributor

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.

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 ArneBab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s a good catch! 👍

Thank you for the fix!

@ArneBab ArneBab merged commit bb492f4 into hyphanet:next Apr 6, 2025
@Bombe Bombe deleted the fix/jar-class-loader-find-directory-resources branch June 29, 2025 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants