Skip to content

fix: implement Node.getRepository() via local repository manager lookup - #13159

Merged
gnodet merged 3 commits into
apache:maven-4.0.xfrom
gnodet:backport/node-repository-impl-to-4.0.x
Sep 17, 2026
Merged

gnodet merged 3 commits into
apache:maven-4.0.xfrom
gnodet:backport/node-repository-impl-to-4.0.x

Conversation

@gnodet

@gnodet gnodet commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Backport of #13153 to maven-4.0.x.

Cherry-pick of ada2740, applied cleanly with no conflicts.

* fix: implement Node.getRepository() via local repository manager lookup

* Address review: improve Javadoc summary and cache repos local variable
@gnodet gnodet added enhancement New feature or request backport labels Sep 16, 2026
@gnodet gnodet added this to the 4.0.0-rc-7 milestone Sep 16, 2026

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean backport of ada2740 — implementation is correct for the standard LRM path. Two items worth addressing before merge.

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

Comment thread impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultNode.java Outdated
Comment thread impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultNodeTest.java Outdated

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Both findings from the previous review are addressed — null guard via Optional.ofNullable(result) is correct, and the tests now use ArgumentCaptor to validate request construction. Two observations before merge.

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

Comment thread impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultNode.java Outdated
Comment thread impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultNode.java Outdated
- Add cachedRepository field to DefaultNode for lazy memoization: avoids
  repeated disk I/O (LRM .repositories file reads) on multi-call scenarios
- Switch to Optional.ofNullable(result).map(...) chain — also handles
  non-standard LRM implementations that return null from find()
- Extend Node.getRepository() Javadoc @return to mention that LRMs
  which do not track artifact origins (e.g. SimpleLocalRepositoryManager)
  always return empty
- Add testGetRepositoryReturnsEmptyWhenLrmReturnsNull and
  testGetRepositoryIsCached tests

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All findings from the previous two rounds are addressed.

  • ✅ Optional.ofNullable(result) guards against null find() return — plus a dedicated test (testGetRepositoryReturnsEmptyWhenLrmReturnsNull)
  • ✅ ArgumentCaptor<LocalArtifactRequest> in both applicable tests — artifact and repo list are now verified
  • ✅ Node.java @return Javadoc extended to document the SimpleLocalRepositoryManager limitation
  • ✅ cachedRepository field added — LRM disk lookup is now deferred and memoized; testGetRepositoryIsCached confirms exactly one find() call across multiple invocations

The implementation is correct: lrm.find() is the right mechanism, all guard conditions are in place, and the six tests cover every branch. Notably the null guard on result makes the backport marginally more defensive than the current master implementation.

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

@gnodet
gnodet merged commit b0a1318 into apache:maven-4.0.x Sep 17, 2026
22 checks passed
gnodet added a commit that referenced this pull request Sep 17, 2026
…ory() (#13162)

Forward-port of hardening applied to the maven-4.0.x backport (PR #13159):
- Use Optional.ofNullable(result).map(...) chain instead of result.getRepository()
  directly, protecting against third-party LRM implementations returning null
- Strengthen tests with ArgumentCaptor to verify LocalArtifactRequest content
- Add testGetRepositoryReturnsEmptyWhenLrmReturnsNull to cover the null-result path
@gnodet gnodet added bug Something isn't working and removed enhancement New feature or request labels Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants