From c67e235399eda13430214a6d8c674839cf805b7b Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Thu, 19 Nov 2026 16:51:29 +0100 Subject: [PATCH 1/2] 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 --- sentry/src/main/java/io/sentry/protocol/Contexts.java | 1 - .../src/test/java/io/sentry/protocol/ContextsTest.kt | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sentry/src/main/java/io/sentry/protocol/Contexts.java b/sentry/src/main/java/io/sentry/protocol/Contexts.java index 0ca6d77ec8d..342f7861357 100644 --- a/sentry/src/main/java/io/sentry/protocol/Contexts.java +++ b/sentry/src/main/java/io/sentry/protocol/Contexts.java @@ -94,7 +94,6 @@ public void setTrace(final @NotNull SpanContext traceContext) { } public void setProfile(final @Nullable ProfileContext profileContext) { - Objects.requireNonNull(profileContext, "profileContext is required"); this.put(ProfileContext.TYPE, profileContext); } diff --git a/sentry/src/test/java/io/sentry/protocol/ContextsTest.kt b/sentry/src/test/java/io/sentry/protocol/ContextsTest.kt index 7a3f425e997..37b751405a9 100644 --- a/sentry/src/test/java/io/sentry/protocol/ContextsTest.kt +++ b/sentry/src/test/java/io/sentry/protocol/ContextsTest.kt @@ -1,5 +1,6 @@ package io.sentry.protocol +import com.google.common.truth.Truth.assertThat import io.sentry.ProfileContext import io.sentry.SpanContext import kotlin.test.Test @@ -149,4 +150,14 @@ class ContextsTest { assertTrue(contexts.isEmpty) } + + @Test + fun `set null profile removes the previous profile context`() { + val contexts = Contexts() + contexts.profile = ProfileContext(SentryId()) + + contexts.profile = null + + assertThat(contexts.profile).isNull() + } } From b5146983fadf2359319c7457e4a483cb762665b2 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Thu, 19 Nov 2026 16:51:53 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f3733039ad..cf683231db4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -143,6 +143,7 @@ - Nav3: Stop attributing errors and spans from an Activity or ViewPager2 page without a `SentryNavEffect` to the most recently visited Nav3 root ([#6483](https://github.com/getsentry/sentry-java/pull/6483)) - Android: Count deep sleep in breadcrumb, screenshot and view hierarchy debounce windows, so the first low-memory or battery breadcrumb after a long Doze is no longer dropped ([#6590](https://github.com/getsentry/sentry-java/pull/6590)) - Avoid duplicate serialization debug logs when calculating serialized object sizes ([#6255](https://github.com/getsentry/sentry-java/pull/6255)) +- `Contexts.setProfile(null)` now removes the profile context instead of throwing ([#6684](https://github.com/getsentry/sentry-java/pull/6684)) ### Dependencies