Repository navigation
Fix NPE when Spring messaging handler is invoked with a null message (quick fix) - #12690
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>
🟢 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. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
jordan-wong
left a comment
There was a problem hiding this comment.
LGTM thanks for this
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
Build pipeline has failing jobs for 38a4ef3: What to do next?
DetailsSince those jobs are not marked as being allowed to fail, the pipeline will most likely fail. |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
Build pipeline has failing jobs for e8e7685: What to do next?
DetailsSince those jobs are not marked as being allowed to fail, the pipeline will most likely fail. |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
Build pipeline has failing jobs for 380da2e: What to do next?
DetailsSince those jobs are not marked as being allowed to fail, the pipeline will most likely fail. |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
Build pipeline has failing jobs for db683de: What to do next?
DetailsSince those jobs are not marked as being allowed to fail, the pipeline will most likely fail. |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
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. 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