Fix operator precedence skipping type=bom dependency imports - #12722
Conversation
gnodet
left a comment
There was a problem hiding this comment.
Clean, well-scoped bug fix for operator precedence in importDependencyManagement that silently skipped type=bom dependencies. The fix is logically correct, the regression test adequately covers the scenario, and the validator update is consistent.
Non-blocking observations:
-
Validator assertion drift (low): The existing
testBadImportScopeTypeassertion checks for substring"must be 'pom'"which still passes against the new message"must be 'pom' or 'bom'..."but doesn't verify the updated text. Consider updating the assertion to match the new full message. -
Pre-existing cycle message (low): The cycle detection message says "The dependencies of type=pom and with scope=import form a cycle" — now that
type=bomis also processed, this could be misleading for bom-typed cycles. Not introduced by this PR. -
Nice design choice: The PR's expression
!((pom || bom) && import)is semantically cleaner than the alternative!(pom && import) && !bomsuggested in the issue — the latter would have incorrectly allowedtype=bomentries withoutscope=importto pass through the filter.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of gnodet
gnodet
left a comment
There was a problem hiding this comment.
Clean, well-scoped bug fix for operator precedence in importDependencyManagement that silently skipped type=bom import-scoped dependencies. The logic fix is verified correct, the regression test adequately covers the scenario, and the validator update is consistent.
Minor observations (non-blocking):
- The existing
testBadImportScopeTypeassertion checks for substring"must be 'pom'"which still passes against the new message viaassertContains(substring match), so it does not actually verify the updated validator text. Consider updating the assertion to"must be 'pom' or 'bom'"to confirm the new wording. Not a blocker since no code in this PR touches that test. - The cycle detection message says "The dependencies of type=pom and with scope=import form a cycle" — now that
type=bomis also processed, this message could be misleading for bom-typed cycles. Pre-existing issue, not introduced by this PR. - The fix's expression
!("pom" || "bom") && "import")is semantically cleaner and more correct than the alternative suggested in the issue. - The compat layer (
compat/maven-model-builder) has a similar import check that only handlestype=pom, which is expected sincetype=bomis a Maven 4 concept.
This review was generated by an AI agent (Claude Code) and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
74f27b3 to
8d6018c
Compare
gnodet
left a comment
There was a problem hiding this comment.
Correct operator-precedence fix for type=bom dependency imports
The original bug (introduced in commit d075fe7, [MNG-8084]) had !("pom" && "import") || "bom" which always evaluated true for type=bom entries, causing the continue to fire unconditionally and silently skip all BOM imports. The fix correctly rewrites this as !("pom" || "bom") && "import"), properly processing both pom and bom typed imports.
Key observations:
- The
DefaultModelValidatoris updated consistently to accept bothpomandbomtypes - The compat layer (
maven-model-builder) correctly only tests forpomsince type=bom is a Maven 4 concept - The regression test with a dedicated POM fixture adequately covers the scenario
- Single squashed commit with clean history
No issues found.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
importDependencyManagement treated BOM-typed import-scoped dependencies as non-imports because `|| "bom".equals(...)` made the continue branch always true for type=bom. Accept pom or bom with import scope, align validator messaging, and cover with a regression test. Fixes apache#12589
8d6018c to
6aaeb51
Compare
The bom type inherently implies import semantics (unlike type=pom which needs scope=import). Change the filter from (pom || bom) && import to (pom && import) || bom, and update the test to verify that type=bom alone is sufficient. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Pushed a fixup commit: The Changes:
All 579 tests in |
gnodet
left a comment
There was a problem hiding this comment.
Thanks for fixing the operator-precedence bug in importDependencyManagement — that fix is correct and the test is clear 👍
However, the validator change in DefaultModelValidator looks wrong to me.
The validator check at line 1195-1196 is guarded by if ("import".equals(dependency.getScope())), so it only fires when scope=import is explicitly set. Adding "bom" there:
if (!"pom".equals(dependency.getType()) && !"bom".equals(dependency.getType())) {
// "must be 'pom' or 'bom' to import the managed dependencies."implies that type=bom requires scope=import — but your own builder fix and test demonstrate the opposite: type=bom inherently implies import semantics and does not need scope=import (the test POM import-bom-type.xml has <type>bom</type> without any <scope>import</scope>).
Concretely:
| Scenario | Builder processes it? | Validator behavior (with this PR) |
|---|---|---|
type=bom (no scope) |
✅ yes — correct | No warning (good — this block isn't entered) |
type=bom + scope=import |
✅ yes | Silently accepted — message says bom is a valid import type |
type=pom + scope=import |
✅ yes | Silently accepted |
The second row is the problem: scope=import is redundant with type=bom, but the validator now frames bom as just another valid type that needs scope=import to work. The warning message "must be 'pom' or 'bom' to import" reinforces this misunderstanding.
Since type=bom doesn't require scope=import, I'd suggest dropping the validator change entirely. The original check (type must be 'pom' when scope=import) is still correct — scope=import is specific to type=pom. If someone writes the redundant type=bom, scope=import, the existing warning is actually helpful because it nudges them toward the correct pattern (just type=bom, no scope needed).
The import-scope validator check fires only when scope=import is set. Adding bom there incorrectly implies that type=bom requires scope=import, but bom inherently implies import semantics and works without it. The original check (type must be 'pom' for scope=import) is correct. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…#12930) * Fix operator precedence skipping type=bom dependency imports importDependencyManagement treated BOM-typed import-scoped dependencies as non-imports because `|| "bom".equals(...)` made the continue branch always true for type=bom. Accept pom or bom with import scope, align validator messaging, and cover with a regression test. Fixes #12589 * type=bom does not require scope=import for dependency management import The bom type inherently implies import semantics (unlike type=pom which needs scope=import). Change the filter from (pom || bom) && import to (pom && import) || bom, and update the test to verify that type=bom alone is sufficient. * Revert validator change: bom type does not require scope=import The import-scope validator check fires only when scope=import is set. Adding bom there incorrectly implies that type=bom requires scope=import, but bom inherently implies import semantics and works without it. The original check (type must be 'pom' for scope=import) is correct. --------- Co-authored-by: Burak Kalaycı <kalayciburak1996@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
importDependencyManagementskipped every dependency withtype=bombecause of operator precedence:For
type=bomthe|| bomterm is always true, so BOM-typed import-scoped entries never load managed dependencies. Maven 4 definesType.BOM(mapped to thepomextension), so these imports should be processed the same way astype=pom+scope=import.This change:
(pom || bom) && importas an import BOM/POM entrytype=bomin the import-scope validator message (warning only for other types)type=bomFixes #12589
Checklist
mvn verifyto make sure basic checks pass.Test plan
Executed:
Result: 98 tests, 0 failures (includes new
testImportScopeBomTypeIsProcessed).