Skip to content

Commit bb056cc

Browse files
adinauerclaude
andcommitted
fix: Detect integer attribute type correctly for all integer Number subtypes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 12d88f2 commit bb056cc

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

sentry/src/main/java/io/sentry/SentryAttributeType.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package io.sentry;
22

3+
import java.math.BigInteger;
34
import java.util.Locale;
5+
import java.util.concurrent.atomic.AtomicInteger;
6+
import java.util.concurrent.atomic.AtomicLong;
47
import org.jetbrains.annotations.NotNull;
58
import org.jetbrains.annotations.Nullable;
69

@@ -18,7 +21,13 @@ public enum SentryAttributeType {
1821
if (value instanceof Boolean) {
1922
return BOOLEAN;
2023
}
21-
if (value instanceof Integer) {
24+
if (value instanceof Integer
25+
|| value instanceof Long
26+
|| value instanceof Short
27+
|| value instanceof Byte
28+
|| value instanceof BigInteger
29+
|| value instanceof AtomicInteger
30+
|| value instanceof AtomicLong) {
2231
return INTEGER;
2332
}
2433
if (value instanceof Number) {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.sentry
2+
3+
import java.math.BigDecimal
4+
import java.math.BigInteger
5+
import java.util.concurrent.atomic.AtomicInteger
6+
import java.util.concurrent.atomic.AtomicLong
7+
import kotlin.test.Test
8+
import kotlin.test.assertEquals
9+
10+
class SentryAttributeTypeTest {
11+
12+
@Test
13+
fun `inferFrom returns BOOLEAN for Boolean`() {
14+
assertEquals(SentryAttributeType.BOOLEAN, SentryAttributeType.inferFrom(true))
15+
assertEquals(SentryAttributeType.BOOLEAN, SentryAttributeType.inferFrom(false))
16+
}
17+
18+
@Test
19+
fun `inferFrom returns INTEGER for Integer`() {
20+
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(42))
21+
}
22+
23+
@Test
24+
fun `inferFrom returns INTEGER for Long`() {
25+
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(42L))
26+
}
27+
28+
@Test
29+
fun `inferFrom returns INTEGER for Short`() {
30+
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(42.toShort()))
31+
}
32+
33+
@Test
34+
fun `inferFrom returns INTEGER for Byte`() {
35+
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(42.toByte()))
36+
}
37+
38+
@Test
39+
fun `inferFrom returns INTEGER for BigInteger`() {
40+
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(BigInteger.valueOf(42)))
41+
}
42+
43+
@Test
44+
fun `inferFrom returns INTEGER for AtomicInteger`() {
45+
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(AtomicInteger(42)))
46+
}
47+
48+
@Test
49+
fun `inferFrom returns INTEGER for AtomicLong`() {
50+
assertEquals(SentryAttributeType.INTEGER, SentryAttributeType.inferFrom(AtomicLong(42)))
51+
}
52+
53+
@Test
54+
fun `inferFrom returns DOUBLE for Double`() {
55+
assertEquals(SentryAttributeType.DOUBLE, SentryAttributeType.inferFrom(3.14))
56+
}
57+
58+
@Test
59+
fun `inferFrom returns DOUBLE for Float`() {
60+
assertEquals(SentryAttributeType.DOUBLE, SentryAttributeType.inferFrom(3.14f))
61+
}
62+
63+
@Test
64+
fun `inferFrom returns DOUBLE for BigDecimal`() {
65+
assertEquals(
66+
SentryAttributeType.DOUBLE,
67+
SentryAttributeType.inferFrom(BigDecimal.valueOf(3.14)),
68+
)
69+
}
70+
71+
@Test
72+
fun `inferFrom returns STRING for String`() {
73+
assertEquals(SentryAttributeType.STRING, SentryAttributeType.inferFrom("hello"))
74+
}
75+
76+
@Test
77+
fun `inferFrom returns STRING for null`() {
78+
assertEquals(SentryAttributeType.STRING, SentryAttributeType.inferFrom(null))
79+
}
80+
}

0 commit comments

Comments
 (0)