I am facing a problem while storing arrays in setter method. I tried to resolve this issue by solution like below.
Problem:
public void setMyArray(String[] myArray) {
this.myArray = myArray;
}
Solution:
public void setMyArray(String[] newMyArray) {
if (newMyArray == null) {
this.myArray = new String[0];
} else {
this.myArray = Arrays.copyOf(newMyArray, newMyArray.length);
}
}
I also tried with clone()
method as described in below link
Sonar Violation: Security - Array is stored directly
but is of no use to get rid of sonar violation. Please suggest me some methods. Thanks in advance