Malicious code vulnerability - May expose internal representation by returning reference to mutable object(恶意代码漏洞 - 可能通过返回对可变对象的引用来暴露内部表示)
问题描述
您好,我的违规行为如下:
Hi I'm getting the violation as below:
恶意代码漏洞 - 可能会通过以下方式暴露内部表示返回对可变对象的引用
Malicious code vulnerability - May expose internal representation by returning reference to mutable object
在我的代码中我是这样写的
in my code i wrote like this
public String[] chkBox() {
return chkBox;
}
我们如何解决它.
推荐答案
正如错误消息所述,您正在返回内部状态(chkBox 很可能是对象内部状态的一部分,即使您不是显示它的定义)
As the error message states, you're returning internal state (chkBox is - most likely - part of the internal state of an object even though you're not showing its definition)
这可能会导致问题 - 例如 - 这样做
This can cause problems if you - for example - do
String[] box = obj.chkBox();
box[0] = null;
由于数组对象和所有 Java 对象一样,都是通过引用传递的,这也会改变存储在对象中的原始数组.
Since an array object, as all Java objects, is passed by reference, this will change the original array stored inside your object as well.
您最可能想要解决此问题的方法很简单
What you most likely want to do to fix this is a simple
return (String[])chkBox.clone();
返回数组的副本而不是实际的数组.
which returns a copy of the array instead of the actual array.
这篇关于恶意代码漏洞 - 可能通过返回对可变对象的引用来暴露内部表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:恶意代码漏洞 - 可能通过返回对可变对象的引用来暴露内部表示


- C++ 和 Java 进程之间的共享内存 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01