Skip to content

Fix #13985: Do not reuse imported dependency management cached without locations - #13988

Merged
cstamas merged 1 commit into
apache:maven-3.10.xfrom
dodoshell:fix-13985-bom-import-location-tracking
Nov 17, 2026
Merged

cstamas merged 1 commit into
apache:maven-3.10.xfrom
dodoshell:fix-13985-bom-import-location-tracking

Conversation

@dodoshell

Copy link
Copy Markdown
Contributor

The dependency management of an imported BOM is cached under groupId:artifactId:version and the import tag, whatever the location tracking of the build that imported it. The model cache lives for the whole session, so when the BOM is first imported by a model built without location tracking (e.g. the POM of a build extension, read through the artifact descriptor reader), a later project build with location tracking reuses that copy and the managed dependencies it contributes have no InputLocation.

This caches the dependency management of builds with location tracking under a separate tag, import-with-locations, so they never pick up a copy without locations. Builds without location tracking keep using the existing import tag.

Added a test in DefaultModelBuilderTest that builds a POM importing a BOM twice with the same ModelCache, first without and then with location tracking, and checks that the managed dependency version has a location. It fails without the change.

The raw parent cache (ModelCacheTag.RAW in readParent) is keyed the same way, so a parent resolved from a repository and first read without location tracking can still end up without locations. I left it out to keep this change focused on the reported case; happy to follow up if wanted.

The same code is on maven-3.9.x, so this could be backported there if you think it is worth it. master doesn't seem affected, since the XML parser there always records locations.

Fixes #13985


To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following:

…without locations

The dependency management of an imported BOM was cached under its
groupId:artifactId:version and the "import" tag, whatever the location
tracking of the build that imported it. When the BOM was first imported
by a model built without location tracking, e.g. while reading the POM
of a build extension, a later project build with location tracking
reused that copy, and the managed dependencies it contributed had no
InputLocation.

Cache the dependency management of builds with location tracking under
a separate tag, so they never pick up a copy without locations.

@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.

Clean, minimal fix for a real cache contamination bug. The new IMPORT_WITH_LOCATIONS tag correctly mirrors the existing IMPORT tag, and the tag selection logic is sound. The test properly validates the failure mode.

Metadata suggestions:

  • 🏷️ Suggested milestone: 3.10.2
  • 🔙 Backport: not needed (the issue can't occur on master where the XML parser always records locations)

💡 FYI (no action needed): The same cache contamination pattern exists in the readParent/RAW path — if a parent POM is ever cached without location tracking and later requested with it, the same stale-entry problem would occur. Out of scope for this PR, but worth a follow-up issue.

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

@cstamas cstamas added this to the 3.10.2 milestone Nov 16, 2026
@cstamas
cstamas requested a balanced review from Copilot November 17, 2026 17:41

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the changes separating BOM import cache entries by location-tracking mode.

No open issues 🎉

What changed in this PR

Fixes #13985 by separating imported BOM dependency-management cache entries by location-tracking mode, preventing project builds from reusing entries that lack source locations.

Changes:

  • Adds an import-with-locations cache tag while preserving import for builds without location tracking.
  • Uses the selected tag consistently for cache reads and writes.
  • Adds a regression test that shares a cache between untracked and tracked builds and checks the managed version’s location.
File Description
maven-model-builder/​src/​test/​java/​org/​apache/​maven/​model/​building/​DefaultModelBuilderTest.java Adds the shared-cache regression test and an in-memory cache helper.
maven-model-builder/​src/​main/​java/​org/​apache/​maven/​model/​building/​ModelCacheTag.java Defines the location-aware import cache tag.
maven-model-builder/​src/​main/​java/​org/​apache/​maven/​model/​building/​DefaultModelBuilder.java Selects the import cache tag according to location tracking.

Review effort: Balanced

@cstamas
cstamas merged commit 171a3f4 into apache:maven-3.10.x Nov 17, 2026
15 checks passed
@cstamas cstamas added the bug Something isn't working label Nov 17, 2026
@azouiten-murex

azouiten-murex commented Nov 18, 2026 •

Copy link
Copy Markdown

Hello, Thanks for the fix! Could you please explain to me your release process? When do I expect to have the fix when I download maven binary from official website?

I v just seen that it was on 3.10.x, will it be backported to 3.9.6?

gnodet added a commit that referenced this pull request Nov 24, 2026
…ement cached without locations (#14117)

Backport of #13988 to `maven-4.0.x`.

The dependency management of an imported BOM was cached under its
groupId:artifactId:version and the "import" tag, whatever the location
tracking of the build that imported it. When the BOM was first imported
by a model built without location tracking (e.g. while reading the POM
of a build extension), a later project build with location tracking
reused that copy, and the managed dependencies it contributed had no
InputLocation.

Cache the dependency management of builds with location tracking under
a separate tag, so they never pick up a copy without locations.

Cherry-picked from 171a3f4 (adapted:
test moved from maven-model-builder/ to compat/maven-model-builder/).

Co-authored-by: dodoshell <326978213+dodoshell@users.noreply.github.com>
gnodet added a commit that referenced this pull request Nov 25, 2026
…t locations (#14118)

Port of #13988 (maven-3.10.x) to master.

The dependency management of an imported BOM was cached under its
groupId:artifactId:version and the "import" tag, whatever the location
tracking of the build that imported it. When the BOM was first imported
by a model built without location tracking (e.g. while reading the POM
of a build extension), a later project build with location tracking
reused that copy, and the managed dependencies it contributed had no
InputLocation.

Cache the dependency management of builds with location tracking under
a separate tag, so they never pick up a copy without locations.

---------

Co-authored-by: dodoshell <326978213+dodoshell@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants