Security - Array is stored directly(安全性 - 数组直接存储)
问题描述
我什至提到:声纳违规:安全 - 阵列直接存储一个>
我的代码是--->
public final void setSelectedObjectsList(final ScheduleDTO[] selectedObjectsList)
// Security - Array is stored directly
//The user-supplied array 'selectedObjectsList' is stored directly.
{
if (selectedObjectsList != null) {
this.selectedObjectsList = selectedObjectsList.clone();
} else {
this.selectedObjectsList = null;
}
}
这已经在处理防御副本了,不知道为什么声纳就在函数参数处对我大喊大叫.
This is already taking care of defensive copy wonder why sonar is yelling at me right at function parameter.
这不是重复的声纳违规:安全 - 数组直接存储
再次感谢您的帮助和时间.
Again, Thank-you for your hyelp and time.
推荐答案
不确定 Sonar 的想法,但使用 clone()
进行防御性浅拷贝应该适用于数组,就像 Arrays.copyOf
和 System.arrayCopy()
.
Not sure what Sonar is thinking but defensive shallow copying with clone()
should work fine for arrays, as would Arrays.copyOf
and System.arrayCopy()
.
另一方面,由于您已经将数组称为列表:selectedObjectsList
,您也可以将其设为实际列表并进行一些重构:
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<ScheduleDTO> selectedSchedules) {
this.selectedSchedules = selectedSchedules != null ? new ArrayList<ScheduleDTO>(selectedSchedules) : null;
}
这篇关于安全性 - 数组直接存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:安全性 - 数组直接存储
基础教程推荐
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01