Skip to content

Commit 94afb06

Browse files
adinauerclaude
andcommitted
feat: Add Object[] overload to arrayAttribute factory
The arrayAttribute() factory only accepted Collection<?>, but inferFrom() also handles native Java arrays. Add an Object[] overload so users can pass object arrays like String[] directly without falling back to the untyped named() method. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3e35f04 commit 94afb06

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

sentry/api/sentry.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,6 +2814,7 @@ public final class io/sentry/SentryAppStartProfilingOptions$JsonKeys {
28142814

28152815
public final class io/sentry/SentryAttribute {
28162816
public static fun arrayAttribute (Ljava/lang/String;Ljava/util/Collection;)Lio/sentry/SentryAttribute;
2817+
public static fun arrayAttribute (Ljava/lang/String;[Ljava/lang/Object;)Lio/sentry/SentryAttribute;
28172818
public static fun booleanAttribute (Ljava/lang/String;Ljava/lang/Boolean;)Lio/sentry/SentryAttribute;
28182819
public static fun doubleAttribute (Ljava/lang/String;Ljava/lang/Double;)Lio/sentry/SentryAttribute;
28192820
public fun getName ()Ljava/lang/String;

sentry/src/main/java/io/sentry/SentryAttribute.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,9 @@ private SentryAttribute(
6060
final @NotNull String name, final @Nullable Collection<?> value) {
6161
return new SentryAttribute(name, SentryAttributeType.ARRAY, value);
6262
}
63+
64+
public static @NotNull SentryAttribute arrayAttribute(
65+
final @NotNull String name, final @Nullable Object[] value) {
66+
return new SentryAttribute(name, SentryAttributeType.ARRAY, value);
67+
}
6368
}

sentry/src/test/java/io/sentry/SentryAttributeTypeTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,11 @@ class SentryAttributeTypeTest {
112112
fun `inferFrom returns ARRAY for mixed-type list`() {
113113
assertEquals(SentryAttributeType.ARRAY, SentryAttributeType.inferFrom(listOf("a", 1, true)))
114114
}
115+
116+
@Test
117+
fun `arrayAttribute factory accepts Object array`() {
118+
val attr = SentryAttribute.arrayAttribute("key", arrayOf("a", "b"))
119+
assertEquals("key", attr.name)
120+
assertEquals(SentryAttributeType.ARRAY, attr.type)
121+
}
115122
}

0 commit comments

Comments
 (0)