Skip to content

Commit c67e235

Browse files
runningcodeclaude
andcommitted
fix(protocol): Allow Contexts.setProfile(null) to clear the profile context
setProfile takes a @nullable ProfileContext but threw on null. Drop the requireNonNull so a null argument removes the profile context, the same as Contexts.put does for any other key. Fixes JAVA-705 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 75718b7 commit c67e235

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎sentry/src/main/java/io/sentry/protocol/Contexts.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ public void setTrace(final @NotNull SpanContext traceContext) {
9494
}
9595

9696
public void setProfile(final @Nullable ProfileContext profileContext) {
97-
Objects.requireNonNull(profileContext, "profileContext is required");
9897
this.put(ProfileContext.TYPE, profileContext);
9998
}
10099

‎sentry/src/test/java/io/sentry/protocol/ContextsTest.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.protocol
22

3+
import com.google.common.truth.Truth.assertThat
34
import io.sentry.ProfileContext
45
import io.sentry.SpanContext
56
import kotlin.test.Test
@@ -149,4 +150,14 @@ class ContextsTest {
149150

150151
assertTrue(contexts.isEmpty)
151152
}
153+
154+
@Test
155+
fun `set null profile removes the previous profile context`() {
156+
val contexts = Contexts()
157+
contexts.profile = ProfileContext(SentryId())
158+
159+
contexts.profile = null
160+
161+
assertThat(contexts.profile).isNull()
162+
}
152163
}

0 commit comments

Comments
 (0)