diff --git a/CHANGELOG.md b/CHANGELOG.md index d2eacae4275..d64209bed76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ ### Fixes - Android: A crash long after `Sentry.init` is no longer marked as a startup crash when the device slept in between, because the time since init now counts deep sleep ([#6738](https://github.com/getsentry/sentry-java/pull/6738)) +- Session Replay: Replays recovered after a crash no longer list `"null"` as a screen name when the last named frame leaves the buffer ([#6827](https://github.com/getsentry/sentry-java/pull/6827)) ### Internal diff --git a/sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BaseCaptureStrategy.kt b/sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BaseCaptureStrategy.kt index 6b55cab0bb1..046a83d838e 100644 --- a/sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BaseCaptureStrategy.kt +++ b/sentry-android-replay/src/main/java/io/sentry/android/replay/capture/BaseCaptureStrategy.kt @@ -250,7 +250,7 @@ constructor( propertyName: String, crossinline onChange: (propertyName: String?, oldValue: T?, newValue: T?) -> Unit = { _, _, newValue -> - cache?.persistSegmentValues(propertyName, newValue.toString()) + cache?.persistSegmentValues(propertyName, newValue?.toString()) }, ): ReadWriteProperty = object : ReadWriteProperty { diff --git a/sentry-android-replay/src/test/java/io/sentry/android/replay/capture/BufferCaptureStrategyTest.kt b/sentry-android-replay/src/test/java/io/sentry/android/replay/capture/BufferCaptureStrategyTest.kt index a926eb00358..822613c0b89 100644 --- a/sentry-android-replay/src/test/java/io/sentry/android/replay/capture/BufferCaptureStrategyTest.kt +++ b/sentry-android-replay/src/test/java/io/sentry/android/replay/capture/BufferCaptureStrategyTest.kt @@ -2,6 +2,7 @@ package io.sentry.android.replay.capture import android.graphics.Bitmap import android.view.MotionEvent +import com.google.common.truth.Truth.assertThat import io.sentry.DataCategory import io.sentry.IScopes import io.sentry.Scope @@ -16,6 +17,7 @@ import io.sentry.android.replay.GeneratedVideo import io.sentry.android.replay.ReplayCache import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_ID import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_REPLAY_ID +import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_REPLAY_SCREEN_AT_START import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_REPLAY_TYPE import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_TIMESTAMP import io.sentry.android.replay.ReplayFrame @@ -250,6 +252,20 @@ class BufferCaptureStrategyTest { verify(fixture.replayCache).rotate(eq(now - fixture.options.sessionReplay.errorReplayDuration)) } + @Test + fun `clears the persisted screen when the last named frame leaves the buffer`() { + val strategy = fixture.getSut() + strategy.start() + whenever(fixture.replayCache.rotate(any())).thenReturn("HomeActivity", null) + + strategy.onScreenshotRecorded {} + assertThat(fixture.persistedSegment[SEGMENT_KEY_REPLAY_SCREEN_AT_START]) + .isEqualTo("HomeActivity") + + strategy.onScreenshotRecorded {} + assertThat(fixture.persistedSegment[SEGMENT_KEY_REPLAY_SCREEN_AT_START]).isNull() + } + @Test fun `onConfigurationChanged creates new segment and updates config`() { val strategy = fixture.getSut()