Skip to content

fix: guard against null LocalArtifactResult in DefaultNode.getRepository() - #13162

Merged
gnodet merged 1 commit into
apache:masterfrom
gnodet:fix/node-getrepository-null-guard
Sep 17, 2026
Merged

gnodet merged 1 commit into
apache:masterfrom
gnodet:fix/node-getrepository-null-guard

Conversation

@gnodet

@gnodet gnodet commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Forward-port of hardening applied during review of #13159 (maven-4.0.x backport).

Changes

DefaultNode.java

Replace Optional.ofNullable(result.getRepository()) with a proper Optional.ofNullable(result).map(...) chain. LocalRepositoryManager.find() is not annotated @Nonnull in the resolver API contract — a third-party LRM implementation returning null would NPE on the original code. The standard SimpleLocalRepositoryManager always returns a non-null result, so this is a defensive guard for custom implementations.

DefaultNodeTest.java

  • Both tests that call lrm.find() now use ArgumentCaptor<LocalArtifactRequest> and assert that the captured request carries the correct artifact and repositories list. Previously any(LocalArtifactRequest.class) silently accepted any request.
  • Add testGetRepositoryReturnsEmptyWhenLrmReturnsNull to explicitly cover the null-result path.

…ory()

Forward-port of hardening applied to the maven-4.0.x backport (PR apache#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-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.

The fix is correct and the new test coverage is solid.

DefaultNode.java: Replacing Optional.ofNullable(result.getRepository()) with the Optional.ofNullable(result).map(...) chain is the right defensive move. LocalRepositoryManager.find() has no @Nonnull contract guarantee in the resolver API, so a third-party LRM returning null from find() would have NPE'd on the original code. The SimpleLocalRepositoryManager always returns non-null, so this is a safe guard for custom implementations.

DefaultNodeTest.java: The ArgumentCaptor additions properly verify that the LocalArtifactRequest is built with the correct artifact and repository list — previously any(LocalArtifactRequest.class) accepted anything silently. The new testGetRepositoryReturnsEmptyWhenLrmReturnsNull test explicitly covers the null-result path that the fix is protecting against.

Metadata: No milestone is set — this targets master, so milestone 4.1.0 (milestone 25) would be appropriate.

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

@gnodet gnodet added this to the 4.1.0 milestone Sep 17, 2026
@gnodet
gnodet merged commit 65816c1 into apache:master Sep 17, 2026
20 checks passed
@gnodet
gnodet deleted the fix/node-getrepository-null-guard branch September 17, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants