Skip to content

Commit 7db1e42

Browse files
authored
Merge pull request #6684 from getsentry/no/java-705-profilecontext-nullable-setter
fix(protocol): Allow Contexts.setProfile(null) to clear the profile context
2 parents 75718b7 + b514698 commit 7db1e42

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
- 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))
144144
- 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))
145145
- Avoid duplicate serialization debug logs when calculating serialized object sizes ([#6255](https://github.com/getsentry/sentry-java/pull/6255))
146+
- `Contexts.setProfile(null)` now removes the profile context instead of throwing ([#6684](https://github.com/getsentry/sentry-java/pull/6684))
146147

147148
### Dependencies
148149

‎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)