Sonar - Store a copy - Mutable members should not be stored or returned directly
The warning is because you did not give the field an initial value. This is how you should implement the code to ensure immutability using java.util.Collections
.
class ABC {
private List<DEF> defList = Collections.emptyList();
public List<DEF> getDefList() {
return defList;
}
public void setDefList(List<DEF> defList) {
// defensively copy, then make immutable
defList = new ArrayList<>(defList);
this.defList = Collections.unmodifiableList(defList);
}