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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to