问题描述
您好,我的违规行为如下:
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.
这篇关于恶意代码漏洞 - 可能通过返回对可变对象的引用来暴露内部表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)