Skip to content

Package manifest attributes are missing for nested jars without directory entries - #52244

Merged
philwebb merged 2 commits into
spring-projects:4.0.xfrom
janwaleed09:nested-jar-package-manifest
Oct 17, 2026
Merged

philwebb merged 2 commits into
spring-projects:4.0.xfrom
janwaleed09:nested-jar-package-manifest

Conversation

@janwaleed09

Copy link
Copy Markdown
Contributor

When an application runs as an executable jar, packages from some nested jars are defined without their manifest attributes. For example, Package.getImplementationVersion() returns null for org.apache.catalina.startup (tomcat-embed-core) and org.h2 (h2). When the same application runs from the IDE or from the extracted layout, the values are there (11.0.27 and 2.5.252 in my sample app).

JarUrlClassLoader.definePackage only uses the manifest of a jar if the jar contains the class entry and a directory entry for the package. Some jars have no directory entries at all (tomcat-embed-core and h2 are examples), so the package is added to undefinablePackages and later defined by URLClassLoader without any attributes.

The class entry check is enough to find the jar that contains the class, so this change removes the directory entry check. I added a test that loads a class from a nested jar without directory entries.

In a sample app with web, JPA, security and actuator (101 nested jars), 125 packages had no manifest attributes before this change. After it, 124 of them match the extracted layout. The last one, org.slf4j.helpers, has a different cause: log4j-to-slf4j looks up org.slf4j.helpers.Log4jLoggerFactory, which does not exist, so the package is marked as undefinable before a real class from it is loaded. I left that out of this PR, but I'm happy to open an issue for it.

This looks related to #38996, which fixed the same symptom for the application's own classes.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label Oct 15, 2026
@philwebb philwebb self-assigned this Oct 16, 2026
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels Oct 16, 2026
@philwebb philwebb added this to the 4.0.x milestone Oct 16, 2026
@philwebb
philwebb force-pushed the nested-jar-package-manifest branch from 30e667e to 48cf3e0 Compare October 17, 2026 00:06
@philwebb philwebb modified the milestones: 4.0.x, 4.0.9 Oct 17, 2026
@philwebb
philwebb merged commit bba5f11 into spring-projects:4.0.x Oct 17, 2026
1 check failed
@philwebb

Copy link
Copy Markdown
Member

Thanks very much @janwaleed09!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants