Skip to content

Commit 477a0ce

Browse files
mccullsdevflow.devflow-routing-intake
andauthored
Fix bug where calling 'context.with((ImplicitContextKeyed) null)' drops all other elements. (#11672)
Fix bug where calling 'context.with((ImplicitContextKeyed) null)' drops all other elements. Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent 5e04aa9 commit 477a0ce

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

components/context/src/main/java/datadog/context/Context.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ default <T, U> Context with(
155155
*/
156156
default Context with(@Nullable ImplicitContextKeyed value) {
157157
if (value == null) {
158-
return root();
158+
return this;
159159
}
160160
return value.storeInto(this);
161161
}

components/context/src/test/java/datadog/context/ContextTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ void testWith(Context context) {
6060
// Test null value handling
6161
assertDoesNotThrow(
6262
() -> context.with(BOOLEAN_KEY, null), "Null value should not throw exception");
63-
// Test null implicitly keyed value handling
64-
assertDoesNotThrow(() -> context.with(null), "Null implicitly keyed value not throw exception");
63+
// Test null implicitly keyed value handling - should preserve existing context, not discard it
64+
Context withNull = context1.with((ImplicitContextKeyed) null);
65+
assertEquals(
66+
context1, withNull, "Null implicitly keyed value should preserve existing context");
6567
}
6668

6769
@ParameterizedTest

0 commit comments

Comments
 (0)