Skip to content

Commit b90f667

Browse files
authored
fix(replay): Fix IllegalArgumentException when Bitmap is initialized with non-positive values (#4536)
* fix(replay): Fix crash when hasSize returns true for negative values * spotless * Changelog
1 parent 8094503 commit b90f667

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Optimize scope when maxBreadcrumb is 0 ([#4504](https://github.com/getsentry/sentry-java/pull/4504))
88
- Fix javadoc on TransportResult ([#4528](https://github.com/getsentry/sentry-java/pull/4528))
9+
- Session Replay: Fix `IllegalArgumentException` when `Bitmap` is initialized with non-positive values ([#4536](https://github.com/getsentry/sentry-java/pull/4536))
910
- Set thread information on transaction from OpenTelemetry attributes ([#4478](https://github.com/getsentry/sentry-java/pull/4478))
1011

1112
### Internal

sentry-android-replay/src/main/java/io/sentry/android/replay/util/Views.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,4 @@ internal fun View?.removeOnPreDrawListenerSafe(listener: ViewTreeObserver.OnPreD
245245
}
246246
}
247247

248-
internal fun View.hasSize(): Boolean = width != 0 && height != 0
248+
internal fun View.hasSize(): Boolean = width > 0 && height > 0
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.sentry.android.replay.util
2+
3+
import android.view.View
4+
import androidx.test.core.app.ApplicationProvider
5+
import androidx.test.ext.junit.runners.AndroidJUnit4
6+
import kotlin.test.Test
7+
import kotlin.test.assertFalse
8+
import kotlin.test.assertTrue
9+
import org.junit.runner.RunWith
10+
11+
@RunWith(AndroidJUnit4::class)
12+
class ViewsTest {
13+
@Test
14+
fun `hasSize returns true for positive values`() {
15+
val view = View(ApplicationProvider.getApplicationContext())
16+
view.right = 100
17+
view.bottom = 100
18+
assertTrue(view.hasSize())
19+
}
20+
21+
@Test
22+
fun `hasSize returns false for null values`() {
23+
val view = View(ApplicationProvider.getApplicationContext())
24+
view.right = 0
25+
view.bottom = 0
26+
assertFalse(view.hasSize())
27+
}
28+
29+
@Test
30+
fun `hasSize returns false for negative values`() {
31+
val view = View(ApplicationProvider.getApplicationContext())
32+
view.right = -1
33+
view.bottom = -1
34+
assertFalse(view.hasSize())
35+
}
36+
}

0 commit comments

Comments
 (0)