Conversation
ContextPropagationAdvice extracted context from the handler's message argument without a null check, and SpringMessageExtractAdapter dereferenced its carrier unguarded, so a null message threw an NPE on every invocation that had no active span. Skip extraction when the message is null and make the adapter tolerate a null carrier. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
dougqh
marked this pull request as ready for review
September 29, 2026 19:17
Contributor
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Does This Do
Fixes a
NullPointerExceptionin the Spring messaging instrumentation when a handler is invoked with anullmessage.SpringMessageHandlerInstrumentation.ContextPropagationAdvicenow skips context extraction when theMessageargument isnull(message != null && activeSpan() == null), so no extract/attach work is done for it.SpringMessageExtractAdapter.forEachKeynow returns early for anullcarrier instead of dereferencing it.SpringMessageExtractAdapterTest(JUnit 5): null message, message without headers, and key normalization / non-string headers. The null-message case fails without the fix.Motivation
Instrumentation telemetry shows this NPE at
SpringMessageExtractAdapter.forEachKey:37(carrier.getHeaders()), reported as "Failed to handle exception in instrumentation fororg.springframework.messaging.handler.invocation.InvocableHandlerMethod-SpringMessageHandlerInstrumentation$ContextPropagationAdvice". It is steady at about 2-2.8k events an hour (~46k a day), from many services on 1.65 and 1.66 (mostly one customer's EV backend services, plus a futures-markets service). Each report aggregates repeats (one sample hadcount: 1673), so the real number of exceptions thrown is higher.There is nothing to extract from a null message, so no tracing data is lost. The cost is an exception thrown and reported on every such invocation.
Additional Notes
getHeaders()result but not a null carrier. The failure became its own reported advice when Split tracing and context tracking in server and messaging integrations #10767 (v1.61.0) split outContextPropagationAdvice. I could not tell from telemetry which Spring code path passes a null message.if (scope != null) scope.close()), so a skipped extraction is safe.Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: N/A
🤖 Generated with Claude Code