Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Fixes

- Fix attribute type detection for `Long`, `Short`, `Byte`, `BigInteger`, `AtomicInteger`, and `AtomicLong` being incorrectly inferred as `double` instead of `integer` ([#5122](https://github.com/getsentry/sentry-java/pull/5122))
- Fix crash when unregistering `SystemEventsBroadcastReceiver` with try-catch block. ([#5106](https://github.com/getsentry/sentry-java/pull/5106))

## 8.33.0
Expand Down
11 changes: 10 additions & 1 deletion sentry/src/main/java/io/sentry/SentryAttributeType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.sentry;

import java.math.BigInteger;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -18,7 +21,13 @@ public enum SentryAttributeType {
if (value instanceof Boolean) {
return BOOLEAN;
}
if (value instanceof Integer) {
if (value instanceof Integer
|| value instanceof Long
|| value instanceof Short
|| value instanceof Byte
|| value instanceof BigInteger
|| value instanceof AtomicInteger
|| value instanceof AtomicLong) {
return INTEGER;
}
if (value instanceof Number) {
Expand Down
80 changes: 80 additions & 0 deletions sentry/src/test/java/io/sentry/SentryAttributeTypeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.sentry

import java.math.BigDecimal
import java.math.BigInteger
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong
import kotlin.test.Test
import kotlin.test.assertEquals

class SentryAttributeTypeTest {

@Test
fun `inferFrom returns BOOLEAN for Boolean`() {
assertEquals(SentryAttributeType.BOOLEAN, SentryAttributeType.inferFrom(true))
assertEquals(SentryAttributeType.BOOLEAN, SentryAttributeType.inferFrom(false))
}

@Test
fun `inferFrom returns INTEGER for Integer`() {
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(42))
}

@Test
fun `inferFrom returns INTEGER for Long`() {
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(42L))
}

@Test
fun `inferFrom returns INTEGER for Short`() {
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(42.toShort()))
}

@Test
fun `inferFrom returns INTEGER for Byte`() {
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(42.toByte()))
}

@Test
fun `inferFrom returns INTEGER for BigInteger`() {
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(BigInteger.valueOf(42)))
}

@Test
fun `inferFrom returns INTEGER for AtomicInteger`() {
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(AtomicInteger(42)))
}

@Test
fun `inferFrom returns INTEGER for AtomicLong`() {
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(AtomicLong(42)))
}

@Test
fun `inferFrom returns DOUBLE for Double`() {
assertEquals(SentryAttributeType.DOUBLE, SentryAttributeType.inferFrom(3.14))
}

@Test
fun `inferFrom returns DOUBLE for Float`() {
assertEquals(SentryAttributeType.DOUBLE, SentryAttributeType.inferFrom(3.14f))
}

@Test
fun `inferFrom returns DOUBLE for BigDecimal`() {
assertEquals(
SentryAttributeType.DOUBLE,
SentryAttributeType.inferFrom(BigDecimal.valueOf(3.14)),
)
}

@Test
fun `inferFrom returns STRING for String`() {
assertEquals(SentryAttributeType.STRING, SentryAttributeType.inferFrom("hello"))
}

@Test
fun `inferFrom returns STRING for null`() {
assertEquals(SentryAttributeType.STRING, SentryAttributeType.inferFrom(null))
}
}
Loading