File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1718,7 +1718,9 @@ public void setSendDefaultPii(boolean sendDefaultPii) {
17181718 * <p>Passing an empty {@link DataCollection} opts into the documented data-collection defaults.
17191719 */
17201720 public void setDataCollection (final @ NotNull DataCollection dataCollection ) {
1721- this .dataCollection = dataCollection ;
1721+ if (dataCollection != null ) {
1722+ this .dataCollection = dataCollection ;
1723+ }
17221724 }
17231725
17241726 /** Returns the Data Collection policy resolver used by SDK integrations. */
Original file line number Diff line number Diff 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)
You can’t perform that action at this time.
0 commit comments