Skip to content

Fix: be more defensive regarding request traces - #1973

Merged
cstamas merged 1 commit into
apache:masterfrom
cstamas:more-defansive
Jul 17, 2026
Merged

Fix: be more defensive regarding request traces#1973
cstamas merged 1 commit into
apache:masterfrom
cstamas:more-defansive

Conversation

@cstamas

@cstamas cstamas commented Jul 17, 2026

Copy link
Copy Markdown
Member

As they NPE in UTs but would also NPE in calls made by some non-maven callers that usually do not set trace at all.

As they NPE in UTs but would also NPE in calls made by some
non-maven callers that usually do not set trace at all.
@cstamas cstamas added this to the 2.0.21 milestone Jul 17, 2026
@cstamas
cstamas requested a review from gnodet July 17, 2026 11:42
@cstamas cstamas self-assigned this Jul 17, 2026
@cstamas cstamas added the bug Something isn't working label Jul 17, 2026
@cstamas
cstamas marked this pull request as ready for review July 17, 2026 11:42

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

Verdict: ✅ Approve — clean, correct fix for a real NPE.

What this fixes: Stream.findFirst() throws NullPointerException when the first mapped element is null (it internally calls Optional.of(value) which rejects null). When a non-Maven caller doesn't set a trace on its requests, getTrace() returns null and the stream crashes before orElse(null) is ever reached.

What I checked:

  • isReentrant(RequestTrace) is already null-safe — the for-loop condition t != null exits immediately, returning false (i.e., "not re-entrant" → validation runs). So the downstream behavior for null traces was always correct; only the stream extraction was broken.
  • The Objects import was already present — no structural changes needed.
  • Both resolveArtifacts() and resolveMetadata() had the same pattern and both are fixed symmetrically.
  • Single-request overloads (resolveArtifact, collectDependencies, etc.) call isReentrant(request.getTrace()) directly — no stream, no issue.

Minor observation (no action needed): The comment "All requests in a batch share the same trace context, so checking any one is sufficient" is slightly imprecise now that the code specifically seeks the first non-null trace, but this is purely cosmetic.

CI: ✅ 18/18 jobs green.


Reviewed with AI assistance on behalf of @gnodet. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.

gnodet added a commit to gnodet/maven-resolver that referenced this pull request Jul 17, 2026
gnodet added a commit to gnodet/maven-resolver that referenced this pull request Jul 17, 2026
@cstamas
cstamas merged commit 45482a8 into apache:master Jul 17, 2026
20 checks passed
@cstamas
cstamas deleted the more-defansive branch July 17, 2026 12:19
gnodet added a commit to gnodet/maven-resolver that referenced this pull request Jul 17, 2026
gnodet added a commit to gnodet/maven-resolver that referenced this pull request Jul 17, 2026
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.

2 participants