Conversation
GetHttpSessionAdvice used request.getServletContext() as a context store key without a null check. Request copies such as Wicket's ServletRequestCopy and Atmosphere's NoOpsRequest return a session but no servlet context, so the weak map behind the store threw a NullPointerException on every getSession() call. Return early when the context is null, in both the javax and jakarta advice. Also document that ContextStore and WeakMap keys must not be null and mark the key parameters @nonnull. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
dougqh
marked this pull request as ready for review
September 29, 2026 20:04
dougqh
requested review from
AlexeyKuznetsov-DD,
claponcet,
jandro996,
mcculls and
ygree
and removed request for
a team
September 29, 2026 20:04
There was a problem hiding this comment.
This comment has been minimized.
This comment has been minimized.
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. |
mcculls
approved these changes
Sep 29, 2026
ygree
reviewed
Sep 30, 2026
|
|
||
| assertDoesNotThrow( | ||
| () -> | ||
| IastOptOutJakartaHttpServletRequestInstrumentation.GetHttpSessionAdvice.onExit( |
Contributor
There was a problem hiding this comment.
I think there's a slightly better way than just testing the advice directly. I've opened a stacked PR that only changes the tests #12696
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 IAST session-tracking advice when a request has no servlet context.GetHttpSessionAdvice.onExit(in both the javax servlet-3.0 and jakarta servlet-5.0 instrumentations) usedrequest.getServletContext()as a context-store key without a null check. It now returns early when the context isnull.ContextStoreandWeakMapkeys must not benull(Javadoc) and marks the key parameters@Nonnull.GetHttpSessionAdviceTest(JUnit 5) in each of the two servlet modules: it registers a recording IASTApplicationModule, calls the advice with a request whose servlet context isnull, and asserts nothing throws and the module is not called.Motivation
Instrumentation telemetry shows an NPE at
WeakMaps$Adapter.get(reached fromFieldBackedContextStore.get), reported as "Failed to handle exception in instrumentation for ..." withIastOptOutJakartaHttpServletRequestInstrumentation$GetHttpSessionAdvice(and, on 1.61, the AtmosphereNoOpsRequestvariant). It is about 2.9k events a day, from a couple of services.Request copies such as Wicket's
ServletRequestCopyandJavaxUpgradeHttpRequest, and Atmosphere'sNoOpsRequest, return a session fromgetSession()but returnnullfromgetServletContext(). Thatnullwas passed toInstrumentationContext.get(...).get(context); the weak map behind the store rejects null keys and throws. Even with a tolerant store the advice would then have failed oncontext.getEffectiveSessionTrackingModes(), so the guard belongs in the advice. (That the throwing frame is theWeakConcurrentMapnull-key check is inferred: its frame is redacted in the sample.)Additional Notes
WeakMap. A silent null tolerance inWeakMapwould not fix this bug, would only cover one of the three paths inFieldBackedContextStore.get(injected field, per-store weak map, global object store), and would hide null keys, which are bugs in our code, from telemetry.@Nonnullscope: documentation only; nothing enforces it at runtime. Static analysis will not have caught this bug becausegetServletContext()comes from the unannotated servlet API. SpotBugs and Spotless pass on the modules touched (internal-api,agent-bootstrap, both servlet modules); I did not run SpotBugs on every module that callsContextStore, so a new finding at a distant call site would only show up in CI.InstrumentationContext.getthrows outside the agent, so on the unfixed advice the direct call fails, and it returns early with the fix. Confirmed for the javax module by reverting the guard; the jakarta advice is the same code. There is no agent-level test of the advice path.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