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.
Fixes #11398
Pull Request: Fix JDK 21+ test failures by propagating
--add-opensto forked test JVMFixes #11398
Overview
This pull request fixes test failures on JDK 21+ caused by missing module opens
in the forked Surefire JVM.
The change ensures that required
--add-opensoptions are propagated correctlyalongside the JaCoCo agent using Surefire’s supported
@{jacocoArgLine}mechanism.What this PR does
--add-opensJVM options to the existing SurefireargLineWhy this change is needed
Starting with JDK 21, Java enforces strong module encapsulation more strictly.
Tests that rely on reflective access to JDK internals (for example
java.langandjava.lang.reflect) fail withInaccessibleObjectExceptionunless the corresponding modules are explicitly opened at JVM startup.
Although the build already used
@{jacocoArgLine}to inject the JaCoCo agent,the forked test JVM did not receive the required
--add-opensoptions.As a result, tests passed on JDK 17 but failed on JDK 21+.
This change ensures the required JVM options are present at fork time,
which is the only point where module opens are honored by the JVM.
How the change works
The Surefire
argLineconfiguration is extended to include the required--add-opensoptions in addition to@{jacocoArgLine}.This approach:
No production code behavior is affected.
Testing
mvn verifyon JDK 17 and JDK 21unrelated to this change
Checklist
mvn verifyrun (JDK 17 / 21)License Declaration
Apache License Version 2.0, January 2004