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.
Pull Request
Fixes #11581
Title
Remove reflective mutation of InputSource.modelId to comply with JDK 26 (JEP 500)
Description
What this PR does
This pull request removes reflective mutation of the modelId field on
org.apache.maven.api.model.InputSource from DefaultModelBuilder.
The removed code used reflection (setAccessible(true)) to mutate a final
field on a public Maven API model object.
Why this change is needed
Running Maven 4.0.0-rc5 on JDK 26 triggers the following warning even for simple
invocations such as mvn clean:
Final field modelId in class org.apache.maven.api.model.InputSource
has been mutated reflectively
This warning is produced due to JEP 500, which tightens restrictions around
reflective mutation of final fields and will block such behavior in a future
Java release.
Key points:
org.apache.maven.api.model.InputSource is part of Maven’s public API
API model objects are immutable by design
maven-impl must not mutate API objects
Legacy model classes (org.apache.maven.model.*) are intentionally not
accessible from maven-impl
Reflective mutation violates both Maven 4 architecture and upcoming JVM rules
How the issue is resolved
The reflective mutation block in DefaultModelBuilder is removed entirely.
The modelId value is diagnostic metadata and is not required for build
correctness. Removing the mutation:
Preserves API immutability
Removes illegal reflective access
Eliminates JDK 26 warnings
Keeps runtime behavior unchanged for users
There is no valid alternative implementation at this layer that respects both
Maven’s module boundaries and Java’s strong encapsulation.
Scope of the change
Addresses one issue only: illegal reflective mutation of InputSource
No refactoring beyond the affected code block
No API changes
No behavior changes
Checklist Compliance
This pull request addresses a single issue only
Description explains what, how, and why clearly
Commit has a meaningful subject and body
Unit tests
Not added: this change removes illegal reflective access and does not alter
externally observable behavior. There is no reliable unit-test hook to assert
JVM-level reflective warnings.
mvn verify executed locally (with -DskipTests)
Core ITs
Not executed locally due to environment constraints; CI will validate
Change is under ~20 LOC
Verification
Executed locally:
mvn -DskipTests verify
mvn clean
Results:
Build succeeds
JDK 26 reflective mutation warning is no longer emitted
License Declaration
I hereby declare this contribution to be licensed under the
Apache License Version 2.0, January 2004