Fix JPMS split-package error by bundling shims into the main JAR#379
Open
aleruz-dt wants to merge 1 commit intoOWASP:mainfrom
Open
Fix JPMS split-package error by bundling shims into the main JAR#379aleruz-dt wants to merge 1 commit intoOWASP:mainfrom
aleruz-dt wants to merge 1 commit intoOWASP:mainfrom
Conversation
This was referenced Apr 23, 2026
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.
Problem
Since release
20240325.1, the library ships three separate JARs on Maven Central:owasp-java-html-sanitizerjava8-shimjava10-shimBoth
java8-shimandjava10-shimdeclare the packageorg.owasp.shim. When all three JARs are placed on the JPMS module path (Java 9+), the JVM raises a hard error at startup — before any application code runs:This is a split-package violation. JPMS forbids the same package from appearing in more than one named or automatic module, and there is no workaround available to consumers short of keeping the library off the module path entirely.
The issue was first reported in #341 (June 2024). This PR resolves it.
Root Cause
Java8Shimuses reflection at runtime to select the right implementation:This dispatch works correctly on the classpath. The problem is purely structural: JPMS resolves modules — and enforces split-package constraints — at layer instantiation time, before any reflection can execute. Two JARs exporting the same package is unconditionally rejected.
Fix
Use
maven-shade-plugininowasp-java-html-sanitizerto inline both shim JARs into the main artifact at build time.With
org.owasp.shimliving inside a single JAR, JPMS sees one module, one package — no split. The existing reflection-based dispatch inJava8Shimcontinues to work unchanged.Both
java8-shimandjava10-shimremain published on Maven Central as standalone artifacts for backwards compatibility. They are marked<optional>true</optional>in the main module's POM so they no longer appear as transitive dependencies of consumers (their classes are now inlined).An explicit
Automatic-Module-Name: owasp.java.html.sanitizeris added to the JAR manifest so that the module name is stable and independent of the JAR filename, which is the recommended practice for libraries that have not yet migrated to a fullmodule-info.java.Changes
pom.xmlmaven-shade-plugin 3.6.0to<pluginManagement>(required byrequirePluginVersionsenforcer)owasp-java-html-sanitizer/pom.xml<optional>; addAutomatic-Module-Nameto bundle manifestdocs/maven.mdchange_log.mdCompatibility
No source or binary incompatibility for the public API (
org.owasp.html). The following points are worth noting for the release notes:java8-shimandjava10-shimno longer appear in the transitive dependency graph ofowasp-java-html-sanitizer. Projects that inadvertently relied on them as transitives must now declare them explicitly. In practice this is unlikely, asorg.owasp.shimis an internal implementation package.org.owasp.shimis not listed inExport-Packageand was never part of the public OSGi contract. OSGi consumers are unaffected.banDuplicateClassesenforcer rule: this rule is currently commented out in the parent POM with aTODO. The shading intentionally causesorg.owasp.shimclasses to appear in both the shim JARs and the inlined copy inside the main JAR within the reactor build. This is consistent with the existing TODO and does not affect published artifacts.Verification
All tests pass. The OSGi manifest verification (
maven-verifier-plugin) confirmsExport-Package: org.owasp.htmlis present and correct in the shaded JAR.Closes #341