You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Jayesh45-master (via GitHub)" <gi...@apache.org> on 2025/12/28 10:31:32 UTC

[PR] Fix jdk21 tests [maven]

Jayesh45-master opened a new pull request, #11605:
URL: https://github.com/apache/maven/pull/11605

   Fixes #11398
   
   # Pull Request: Fix JDK 21+ test failures by propagating `--add-opens` to forked test JVM
   
   ## 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-opens` options are propagated correctly alongside the JaCoCo agent using Surefire’s supported `@{jacocoArgLine}` mechanism.
   
   ---
   
   ## What this PR does
   
   - Appends required `--add-opens` JVM options to the existing Surefire `argLine`
   - Preserves the current JaCoCo setup and forked JVM behavior
   - Ensures tests relying on reflective access continue to work on JDK 21+
   
   ---
   
   ## Why 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.lang` and `java.lang.reflect`) fail with `InaccessibleObjectException` unless 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 necessary `--add-opens` options. 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 `argLine` configuration in the root `pom.xml` is extended to include the required `--add-opens` options in addition to `@{jacocoArgLine}`. This approach:
   
   - Uses documented Surefire behavior
   - Avoids illegal reflective access at runtime
   - Keeps the change scoped strictly to test execution
   
   No code behavior outside the test JVM is affected.
   
   ---
   
   ## Checklist
   
   - [x] **Single issue addressed**  
     This PR only addresses JDK 21+ test failures caused by missing `--add-opens` in the forked JVM.
   
   - [x] **Clear PR description**  
     The description explains what the change does, how it works, and why it is necessary.
   
   - [x] **Meaningful commits**  
     The commit contains a focused change with a clear subject and explanatory body.  
     (Maintainers may squash on merge.)
   
   - [ ] **Unit tests**  
     No new unit tests were added. The change affects JVM startup configuration rather than functional logic.  
     Existing tests already fail without this change and pass once the fix is applied.
   
   - [x] **`mvn verify` run**  
     The build was verified locally using `mvn verify`.
   
   - [ ] **Core ITs**  
     Core ITs were not executed locally due to environment constraints. CI will execute the full suite.
   
   ---
   
   ## License Declaration
   
   - [x] I hereby declare this contribution to be licensed under the  
     [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix jdk21 tests [maven]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on PR #11605:
URL: https://github.com/apache/maven/pull/11605#issuecomment-3694660924

   Corrections to my previous comment: #11398 said that the issue is reported against Maven 3.9.9. In such case, this pull request needs to be rebased not on `master` or `maven-4.0.x`, but on the `maven-3.9.x` branch (I presume, would need confirmation by a Maven core developer).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix jdk21 tests [maven]

Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz closed pull request #11605: Fix jdk21 tests
URL: https://github.com/apache/maven/pull/11605


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix jdk21 tests [maven]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on PR #11605:
URL: https://github.com/apache/maven/pull/11605#issuecomment-3694656265

   The first commit of this pull request is #11604. Not necessarily a problem, but it should be noted that #11604 would need to be merged first.
   
   Also those two pull requests should be on the top of the `master` branch rather than `maven-4.0.x`. No need to close these pull requests. You can get a clone of the master branch, cherry-pick the commits (take this opportunity for making the two pull requests independent), `push --force` on your clone, click on "edit" on the top of this page, and on the line "Jayesh45-master wants to merge 2 commits into apache:maven-4.0.x" swich back "maven-4.0.x" to "master".


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix jdk21 tests [maven]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on code in PR #11605:
URL: https://github.com/apache/maven/pull/11605#discussion_r2725656772


##########
pom.xml:
##########
@@ -512,6 +512,34 @@ under the License.
           <groupId>org.codehaus.plexus</groupId>
           <artifactId>plexus-component-metadata</artifactId>
           <version>${plexusVersion}</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <configuration>
+            <forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory" />
+            <argLine>-Xmx256m @{jacocoArgLine} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED</argLine>
+            <systemPropertyVariables combine.children="append">
+              <version.toolbox>${toolboxVersion}</version.toolbox>

Review Comment:
   Where property `toolboxVersion` is defianed?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix jdk21 tests [maven]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on PR #11605:
URL: https://github.com/apache/maven/pull/11605#issuecomment-3694688806

   No need to create a new pull request. You can cherry-pick, push force and then click on the "edit" button of this pull request.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix jdk21 tests [maven]

Posted by "Jayesh45-master (via GitHub)" <gi...@apache.org>.
Jayesh45-master commented on PR #11605:
URL: https://github.com/apache/maven/pull/11605#issuecomment-3694714372

   Hi @desruisseaux ,
   
   I’ve updated the pull request based on the discussion and rebased it onto the
   `maven-3.9.x` branch, since the issue is reported against Maven 3.9.9.
   The changes are limited to ensuring the required `--add-opens` options are
   propagated to the forked test JVM alongside the existing JaCoCo setup.
   
   Could you please review the updated changes when you have a moment?
   Thanks for your time and guidance.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix jdk21 tests [maven]

Posted by "slawekjaranowski (via GitHub)" <gi...@apache.org>.
slawekjaranowski commented on PR #11605:
URL: https://github.com/apache/maven/pull/11605#issuecomment-3796864118

   @Jayesh45-master , @desruisseaux I missed something here .... which test in Maven we try to fix by this PR?
   
   We have a build with JDK 25 and I don't see a failing tests?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix jdk21 tests [maven]

Posted by "Jayesh45-master (via GitHub)" <gi...@apache.org>.
Jayesh45-master commented on PR #11605:
URL: https://github.com/apache/maven/pull/11605#issuecomment-3694671065

   @desruisseaux 
   So sir like i have to do the changes in maven.3.x and submit again the pull request


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org