Skip to content

Commit a40c2e4

Browse files
adinauerclaude
andcommitted
fix(core): Preserve Data Collection on null setter
Ignore null assignments so the always-present Data Collection configuration and its current values remain intact. Refs #5666 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b64b91b commit a40c2e4

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,9 @@ public void setSendDefaultPii(boolean sendDefaultPii) {
17151715
* <p>Passing an empty {@link DataCollection} opts into the documented data-collection defaults.
17161716
*/
17171717
public void setDataCollection(final @NotNull DataCollection dataCollection) {
1718-
this.dataCollection = dataCollection;
1718+
if (dataCollection != null) {
1719+
this.dataCollection = dataCollection;
1720+
}
17191721
}
17201722

17211723
/**

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ class SentryOptionsTest {
6767
assertThat(options.dataCollection.userInfo).isFalse()
6868
}
6969

70+
@Test
71+
fun `setting null data collection preserves the current instance`() {
72+
val options = SentryOptions()
73+
val dataCollection = DataCollection().apply { setUserInfo(false) }
74+
options.dataCollection = dataCollection
75+
76+
SentryOptions::class
77+
.java
78+
.getMethod("setDataCollection", DataCollection::class.java)
79+
.invoke(options, null)
80+
81+
assertThat(options.dataCollection).isSameInstanceAs(dataCollection)
82+
assertThat(options.dataCollection.userInfo).isFalse()
83+
}
84+
7085
@Test
7186
fun `when options is initialized, logger is not null`() {
7287
assertNotNull(SentryOptions().logger)

0 commit comments

Comments
 (0)