Skip to content

Commit ea23ccd

Browse files
Copilotkasnder
andcommitted
Address code review feedback - improve defensive coding
Co-authored-by: kasnder <5175206+kasnder@users.noreply.github.com>
1 parent d1bcd81 commit ea23ccd

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

app/src/main/java/net/kollnig/missioncontrol/data/Tracker.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import androidx.annotation.NonNull;
2121

2222
import java.util.ArrayList;
23+
import java.util.Collections;
2324
import java.util.HashSet;
2425
import java.util.List;
2526
import java.util.Set;
@@ -33,7 +34,7 @@ public class Tracker {
3334
public String category;
3435
public Long lastSeen;
3536
public String country;
36-
private List<String> dataTypes = new ArrayList<>();
37+
private List<String> dataTypes;
3738

3839
/**
3940
* Creates class for tracker seen in apps' network traffic
@@ -117,7 +118,7 @@ public Set<String> getHosts() {
117118
* @param dataTypes List of data types
118119
*/
119120
public void setDataTypes(List<String> dataTypes) {
120-
this.dataTypes = dataTypes;
121+
this.dataTypes = dataTypes != null ? new ArrayList<>(dataTypes) : new ArrayList<>();
121122
}
122123

123124
/**
@@ -126,6 +127,6 @@ public void setDataTypes(List<String> dataTypes) {
126127
* @return List of data types
127128
*/
128129
public List<String> getDataTypes() {
129-
return dataTypes;
130+
return dataTypes != null ? Collections.unmodifiableList(dataTypes) : Collections.emptyList();
130131
}
131132
}

app/src/main/java/net/kollnig/missioncontrol/data/TrackerList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ private void loadDisconnectTrackers(Context c) {
546546
private void addTrackerDomain(Tracker tracker, String dom) {
547547
// Check if we have DDG data types for this domain
548548
List<String> dataTypes = domainToDataTypes.get(dom);
549-
if (dataTypes != null && !dataTypes.isEmpty()) {
549+
if (dataTypes != null) {
550550
tracker.setDataTypes(dataTypes);
551551
}
552552

0 commit comments

Comments
 (0)