Skip to content

Commit 11fd621

Browse files
adinauerclaude
andcommitted
fix(core): Preserve mutable breadcrumb data access
Initialize the lazy breadcrumb data map when callers request the full map. This keeps getData() mutable for existing callers while preserving lazy allocation for breadcrumbs that only serialize or read individual values. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent dc1ae1e commit 11fd621

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

sentry/src/main/java/io/sentry/Breadcrumb.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public void setType(@Nullable String type) {
629629
@ApiStatus.Internal
630630
@NotNull
631631
public Map<String, Object> getData() {
632-
return data;
632+
return getOrCreateData();
633633
}
634634

635635
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ class BreadcrumbTest {
332332
breadcrumb.removeData(null)
333333
}
334334

335+
@Test
336+
fun `getData returns mutable map for new breadcrumb`() {
337+
val breadcrumb = Breadcrumb()
338+
339+
breadcrumb.data["k"] = "v"
340+
341+
assertEquals("v", breadcrumb.getData("k"))
342+
}
343+
335344
@Test
336345
fun `concurrent first writes keep all data entries`() {
337346
val breadcrumb = Breadcrumb()

0 commit comments

Comments
 (0)