Skip to content

Commit 250ecca

Browse files
committed
fix(replay): Fix crash when hasSize returns true for negative values
1 parent 0f37c1d commit 250ecca

File tree

2 files changed

+38
-1
lines changed
  • sentry-android-replay/src

2 files changed

+38
-1
lines changed

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

0 commit comments

Comments
 (0)