Skip to content

Conversation

@Jayesh45-master
Copy link

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

@desruisseaux desruisseaux changed the base branch from master to maven-4.0.x December 28, 2025 10:44
@desruisseaux desruisseaux mentioned this pull request Dec 28, 2025
7 tasks
@desruisseaux
Copy link
Contributor

The commit should be on top of the master branch rather than maven-4.0.x. See this comment for instructions.

@Jayesh45-master
Copy link
Author

@desruisseaux
Sir actually the issue raised is based on maven-4.0.x branch it has given in the description and the master branch doesnt have this file default one sir so what can i do it would be helpful and thankyou for your time and guidance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JDK26-Build 28 - Final field modelId in class org.apache.maven.api.model.InputSource has been mutated reflectively

2 participants