I even refered : Sonar Violation: Security - Array is stored directly
My code is as --->
public final void setSelectedObjectsList(final ScheduleD
Not sure what Sonar is thinking but defensive shallow copying with clone()
should work fine for arrays, as would Arrays.copyOf
and System.arrayCopy()
.
On the other hand, since you are already calling the array a list: selectedObjectsList
, you could also make it an actual list and refactor a bit:
public final void setSelectedSchedules(List selectedSchedules) {
this.selectedSchedules = selectedSchedules != null ? new ArrayList(selectedSchedules) : null;
}