Security - Array is stored directly

前端 未结 1 1105
执笔经年
执笔经年 2021-01-13 16:46

I even refered : Sonar Violation: Security - Array is stored directly

My code is as --->

    public final void setSelectedObjectsList(final ScheduleD         


        
1条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 17:15

    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;
    }
    

    0 讨论(0)
提交回复
热议问题