diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f3733039a..cf683231db 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 diff --git a/sentry/src/main/java/io/sentry/protocol/Contexts.java b/sentry/src/main/java/io/sentry/protocol/Contexts.java index 0ca6d77ec8..342f786135 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 7a3f425e99..37b751405a 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() + } }