Skip to content

Fix project validation level handling during parent resolution - #13601

Closed
abdulhannansyed548-cmd wants to merge 5 commits into
apache:masterfrom
abdulhannansyed548-cmd:fix-13395-project-validation-level
Closed

abdulhannansyed548-cmd wants to merge 5 commits into
apache:masterfrom
abdulhannansyed548-cmd:fix-13395-project-validation-level

Conversation

@abdulhannansyed548-cmd

@abdulhannansyed548-cmd abdulhannansyed548-cmd commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #13395.

Summary

  • Propagate the requested validation level through ModelBuilderRequest.
  • Use the explicit validation level for raw and effective model validation, while preserving the existing defaults when it is unset.
  • Add regression coverage for local parent POM resolution with different validation levels and plugin-processing settings.

Testing

  • Production compilation succeeded for the relevant Maven Core modules in local checks.

  • Maven Core test compilation encountered local model-class and classpath errors, so the new regression test has not been confirmed passing locally.

  • Please verify the regression test and full build in CI.

  • I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0).

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ License declaration missing

The pull request description must contain at least one of the following lines with a checked box ([x]):

- [ ] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [ ] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).

This comment will be hidden automatically once the description is fixed.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach is on the right track but there are blocking issues before this can merge.

Critical: request.getValidationLevel() from the compat layer returns Maven 3 numeric constants (e.g. VALIDATION_LEVEL_STRICT = 30), but the SPI ModelValidator uses a different scale where VALIDATION_LEVEL_STRICT = 42. Forwarding the raw int silently downgrades every build-mode validation call from 4.2-strict to Maven-3.0-level. A translation step is needed in DefaultProjectBuilder before the value crosses the API boundary.

Also blocking: validateFileModel was not updated alongside validateRawModel and validateEffectiveModel, leaving the three-phase validation inconsistent.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following up on my earlier review — 5 of the 7 issues have been addressed. The two outdated threads (indentation, import ordering) no longer apply. One critical issue with the domain translation remains.

Addressed:

  • ✅ validateFileModel — all three validate* calls now route through getValidationLevel()
  • ✅ @Nullable + Javadoc — the interface method is now documented
  • ✅ Builder method — now accepts Integer, not int
  • ✅ Test coverage — the hasRelativePathWarning assertion indirectly verifies that the compat→SPI translation actually fires (the warning triggers at >= VALIDATION_LEVEL_MAVEN_4_0 = 40, so only a correctly-translated 42 triggers it, not the raw compat 30)

Still open:

  • ⛔ Domain mismatch fix is broken — see inline comment

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@Shreekar-cloud

Copy link
Copy Markdown
Contributor

Hi @abdulhannansyed548-cmd, I was looking into the review feedback on this PR and worked out a fix on top of your two commits that makes your regression test and the existing project tests pass. I don’t want to open a competing PR on an issue you’ve claimed, so here it is for you to use or adapt: https://github.com/Shreekar-cloud/maven/tree/fix-13395-parent-resolution (single commit 6773436).

With a baseline run without the production changes, testLocalParentResolutionWithValidationLevels fails with “Non-resolvable parent POM”. The cause: for a non-reactor build(File), DefaultProjectBuilder only picks BUILD_EFFECTIVE for processPlugins && STRICT, and DefaultModelBuilder only looks for local parents for build requests (findLocalParent is gated on isBuildRequest()).

The change: (1) pomFile != null now means a project build (repository-resolved artifacts have pomFile == null, so those are unchanged); (2) the validation level is forwarded only for build requests, leaving compat STRICT (30) to the default SPI STRICT (42) and passing lower levels, which have the same values in both APIs, unchanged, so consumer requests keep their old defaults; (3) AbstractMavenProjectTestCase sets a scope manager, since these tests now go through strict effective validation.

Behavior changes worth review: build(File) with default STRICT and processPlugins=false is now validated strictly (as in Maven 3), and workspace project POMs resolved as dependencies are now built as projects. Locally I ran ProjectBuilderTest, the org.apache.maven.project tests and the maven-impl model/cache tests (259 tests in maven-core, 0 failures). I haven’t run the full suite or spotless, so CI is the real check.

Happy to open a PR myself or send a patch if you’d prefer that. Just let me know.

@abdulhannansyed548-cmd

Copy link
Copy Markdown
Contributor Author

@Shreekar-cloud Thanks, Shreekar! I went ahead and applied your proposed fix to my branch and pushed it to PR #13601. I've included the regression test as well. I'm still facing a local test-compilation issue, so I haven't been able to verify the test run yet. Really appreciate you sharing the approach!

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation-level forwarding logic is sound and the domain mismatch fix is correct. One behavioral regression to address.

High — pomFile != null unconditionally yields BUILD_EFFECTIVE

Before this PR, BUILD_EFFECTIVE required pomFile != null && request.isProcessPlugins() && request.getValidationLevel() == ModelBuildingRequest.VALIDATION_LEVEL_STRICT. The validation-level condition was correctly dropped since it's now forwarded separately. However, dropping isProcessPlugins() too is a behavioral change: embedders calling build(File, request) with processPlugins=false previously got CONSUMER_PARENT/CONSUMER_DEPENDENCY request types; they now get BUILD_EFFECTIVE, which changes XML parsing strictness, parent resolution, and repository merging.


Metadata: category=bug, milestone=4.1.0

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment on lines 469 to 472
ModelBuilderRequest.RequestType type = reactorMember || isStandalone || pomFile != null
? ModelBuilderRequest.RequestType.BUILD_EFFECTIVE
: (parent
? ModelBuilderRequest.RequestType.CONSUMER_PARENT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Behavioral regression: pomFile != null is too broad. The isProcessPlugins() guard was removed along with the validation-level condition, but only the latter was made redundant by this PR.

Embedders calling build(File, request) with processPlugins=false now get BUILD_EFFECTIVE instead of CONSUMER_PARENT/CONSUMER_DEPENDENCY. This changes XML parsing strictness, parent resolution, and repository merging — beyond the scope of the validation-level fix.

Suggested change
ModelBuilderRequest.RequestType type = reactorMember || isStandalone || pomFile != null
? ModelBuilderRequest.RequestType.BUILD_EFFECTIVE
: (parent
? ModelBuilderRequest.RequestType.CONSUMER_PARENT
ModelBuilderRequest.RequestType type = reactorMember || isStandalone || (pomFile != null && request.isProcessPlugins())


@Nonnull
RequestType getRequestType();
/**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Missing blank line between getRequestType() and the Javadoc for getValidationLevel(). Every other method in this interface has a blank separator before its Javadoc block.

Suggested change
/**
RequestType getRequestType();
/**

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two issues found in this PR.

1. Minor — missing blank line before Javadoc in ModelBuilderRequest.java

The new getValidationLevel() Javadoc starts immediately after getRequestType(); with no blank line separating them, breaking the consistent formatting style of the interface (every other method declaration has a blank line before its Javadoc).

2. Real bug — test assertion incorrect for (STRICT, processPlugins=false)

When processPlugins=false, DefaultProjectBuilder computes type = CONSUMER_DEPENDENCY (because pomFile != null && request.isProcessPlugins() is false). The validationLevel override is then null (the condition type == BUILD_EFFECTIVE && request.getValidationLevel() != STRICT is false). Inside DefaultModelBuilder.getValidationLevel(), the effective level becomes MINIMAL(0) for a non-build request. With level 0, no relativePath warning is emitted (requires ≥ 40 / MAVEN_4_0). But the assertion assertEquals(validationLevel == VALIDATION_LEVEL_STRICT, hasRelativePathWarning) evaluates to assertEquals(true, false) and fails. Please fix the assertion to account for processPlugins=false producing CONSUMER_DEPENDENCY type, or adjust the test matrix to only include combinations where a warning is actually expected.

This review was generated by an AI agent, Hermès on behalf of @gnodet.


@Nonnull
RequestType getRequestType();
/**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Style: Missing blank line before the Javadoc. Every other method in this interface has a blank line between the previous method declaration and its Javadoc. Please add one here:

Suggested change
/**
/**

Comment on lines +336 to +338
assertEquals(
validationLevel == ModelBuildingRequest.VALIDATION_LEVEL_STRICT,
hasRelativePathWarning,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bug: This assertion is incorrect for (STRICT=30, processPlugins=false).

When processPlugins=false, DefaultProjectBuilder sets type = CONSUMER_DEPENDENCY (the pomFile != null && request.isProcessPlugins() branch is false). The validationLevel override is therefore null, and DefaultModelBuilder.getValidationLevel() falls back to MINIMAL(0) for a non-build request. No relativePath warning is emitted at level 0 (the threshold is MAVEN_4_0 = 40), so hasRelativePathWarning is false — but validationLevel == VALIDATION_LEVEL_STRICT is true (30 == 30), causing the assertion to fail.

The test needs to account for the fact that processPlugins=false suppresses validation regardless of the requested level. Consider adjusting the expected value based on both validationLevel and processPlugins, or narrow the test matrix to only the combinations where a warning is actually produced.

@Shreekar-cloud

Copy link
Copy Markdown
Contributor

Thanks for applying that, @abdulhannansyed548-cmd. I checked out the current head of this PR (aeb6dc1) and ran the regression test, and I found two small things that would likely stop CI from going green:

  1. testLocalParentResolutionWithValidationLevels still fails for processPlugins=false. After the review’s request to keep the isProcessPlugins() guard, a processPlugins=false build is a consumer request again, and consumer requests never look for a local parent. So builder.build(...) throws Non-resolvable parent POM ... test:parent:pom:1 (absent) at ProjectBuilderTest.java:325 before any assertion runs. The updated expected value doesn’t help because the build throws before it’s checked. I changed the loop to for (boolean processPlugins : List.of(true)) (and nothing else), and with that the test passes: Tests run: 1, Failures: 0, Errors: 0. The remaining matrix is MINIMAL and STRICT with processPlugins=true, which are the combinations where a local parent is expected.

  2. Formatting. When I ran the build locally, the formatter rewrote the type assignment in DefaultProjectBuilder.prepare(). This is the formatted version, with the same logic:

java
ModelBuilderRequest.RequestType type =
reactorMember || isStandalone || (pomFile != null && request.isProcessPlugins())
? ModelBuilderRequest.RequestType.BUILD_EFFECTIVE
: (parent
? ModelBuilderRequest.RequestType.CONSUMER_PARENT
: ModelBuilderRequest.RequestType.CONSUMER_DEPENDENCY);

Running mvn spotless:apply (or any normal build) will apply it. The bot’s earlier note about the missing blank line before the getValidationLevel() Javadoc in ModelBuilderRequest.java is still open too.

Caveat: I only ran that one test on your branch, not the full suite, so CI is still the real check.

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix — the root cause analysis is correct: the RequestType selection in DefaultProjectBuilder should not depend on validationLevel, and decoupling them is the right move.

However, adding Integer getValidationLevel() to the public ModelBuilderRequest API breaks the encapsulation that RequestType was designed to provide. The whole point of the API was for callers to express their intent, and have the implementation decide the validation level internally. A nullable Integer leaks implementation details (numeric validation level constants) into the public contract, and the compat layer comment itself acknowledges the mismatch ("Maven 3 STRICT (30) is not the SPI STRICT (42)").

A cleaner alternative would be to add a new RequestType enum value — something like LOAD_PROJECT — that captures the IDE use case: "I'm loading a project from a local POM file and need profile activation and user properties, but I don't need strict build-time validation." The DefaultModelBuilder would then map this request type to VALIDATION_LEVEL_MINIMAL internally, just like it already does for CONSUMER_PARENT / CONSUMER_DEPENDENCY. No validation level on the API surface.

This keeps the design principle intact: RequestType captures caller intent, the implementation decides validation strictness.

The DefaultProjectBuilder compat layer would then map:

  • processPlugins=true && validationLevel==STRICT → BUILD_EFFECTIVE
  • processPlugins=true && validationLevel!=STRICT → LOAD_PROJECT (or whatever name fits best)
  • parent resolution → CONSUMER_PARENT
  • dependency resolution → CONSUMER_DEPENDENCY

Fully automatic review from Claude Code

@Shreekar-cloud

Copy link
Copy Markdown
Contributor

@abdulhannansyed548-cmd, following gnodet's review I'm preparing the LOAD_PROJECT variant on top of your branch and will run the tests on my side (Windows, JDK 25). I'll share a tested branch in a day or two. If you'd rather do it yourself or are already on it, just tell me and I'll send my notes instead.

@abdulhannansyed548-cmd

Copy link
Copy Markdown
Contributor Author

@Shreekar-cloud Thanks, Shreekar! I'm already working on the LOAD_PROJECT changes following gnodet's review. Since you can run the tests on Windows with JDK 25, I'd appreciate it if you could share your tested branch and notes once they're ready. I'll avoid making further changes until I can compare the implementations. Thanks for helping with this!

@Shreekar-cloud

Shreekar-cloud commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Hi @abdulhannansyed548-cmd, thanks for building on this and for waiting. I applied the LOAD_PROJECT approach on top of your head (aeb6dc1) and pushed it here:

https://github.com/Shreekar-cloud/maven/tree/fix-13395-load-project

What it does:

  • Adds RequestType.LOAD_PROJECT. It gets the project treatment (local parent lookup, profile activation) but is parsed and validated leniently.
  • Reactor and standalone builds stay BUILD_EFFECTIVE. A POM file with processPlugins on becomes BUILD_EFFECTIVE if the validation level is STRICT, and LOAD_PROJECT otherwise.
  • Drops the getValidationLevel() API additions, so CacheConfigurationTest and AbstractMavenProjectTestCase go back to their originals.
  • Keeps your regression test, with the processPlugins loop reduced to true.

Testing: ProjectBuilderTest#testLocalParentResolutionWithValidationLevels passes, and the maven-core, model and cache tests pass (259 run, 0 failures, 1 skipped).

How would you like to handle it? You can take these changes into your PR, or I can open a separate PR that credits you as co-author so the maintainers can pick one. Either works for me. I'll wait for your answer before opening anything.

Notes for review:

  • LOAD_PROJECT is treated as a build request everywhere in DefaultModelBuilder (local parent lookup, pomFile handling, profile activation, raw model transform, repository precedence), except for XML parsing strictness and validation, which stay lenient like the consumer requests.
  • Reactor and standalone builds stay BUILD_EFFECTIVE, so they are not weakened.
  • A POM file with processPlugins on becomes BUILD_EFFECTIVE if the validation level is STRICT, and LOAD_PROJECT otherwise. Every non-STRICT compat level gets MINIMAL validation, which is what it got before.
  • Tested locally (Windows, JDK 25): the regression test and the maven-core, model and cache tests. I haven't run the full suite or CI on this branch.

@abdulhannansyed548-cmd

Copy link
Copy Markdown
Contributor Author

@Shreekar-cloud Thanks a lot for taking the time to build on my work and validate the LOAD_PROJECT approach, especially by running the tests on Windows with JDK 25. I really appreciate the collaboration and the detailed notes explaining the design decisions.

Please go ahead and open the separate PR, crediting me as co-author as you suggested. I’ll review the changes carefully and coordinate with the maintainers so we can avoid duplicate work and make the review process as smooth as possible.

Thanks again for your help and for making this a great learning experience for me!

@Shreekar-cloud

Copy link
Copy Markdown
Contributor

@abdulhannansyed548-cmd Thanks, Abdul! I've opened #13669 with the LOAD_PROJECT change, with you credited as co-author. Whichever PR the maintainers prefer is fine with me.

@gnodet

gnodet commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Superseded by #13669

@gnodet gnodet closed this Oct 22, 2026
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.

v3 ProjectBuilder classifies a project built from its POM file as a dependency unless validation is STRICT

4 participants