public class Test { private String[] name; //如果name的类型为String 就不会有bug提示 public String[] getName() {
return this.name;
} public void setName(String[] name) {
this.name = name;
}
}
///下面是findbug的错误提示:英文不是太好,看的不是很明白
May expose internal representation by incorporating reference to mutable object</b><br/><p> This code stores a reference to an externally mutable object into the
internal representation of the object.
If instances
are accessed by untrusted code, and unchecked changes to
the mutable object would compromise security or other
important properties, you will need to do something different.
Storing a copy of the object is better approach in many situations为什么把name的类型改为String后,就没有bug提示了?
return this.name;
} public void setName(String[] name) {
this.name = name;
}
}
///下面是findbug的错误提示:英文不是太好,看的不是很明白
May expose internal representation by incorporating reference to mutable object</b><br/><p> This code stores a reference to an externally mutable object into the
internal representation of the object.
If instances
are accessed by untrusted code, and unchecked changes to
the mutable object would compromise security or other
important properties, you will need to do something different.
Storing a copy of the object is better approach in many situations为什么把name的类型改为String后,就没有bug提示了?
解决方案 »
- RCP 快捷键冲突
- 环境变量配置时那个百分号是什么意思,起什么作用?
- 新手提问:在命令行里不能运行eclipse生成的class文件?
- 求spring jdbctemplate 调用数据库连接池的例子
- 使用JGraph在网页上显示拓扑图并添加鼠标事件的问题
- 一道英文题,高手进,谢谢帮忙
- 新手,不明白读数据库的问题,请教(内含出错代码行)
- [菜鸟提问]请问在Java中怎样实现在文本中存取数据?
- oxfordxy 谢谢 你的资料 请你来接分
- 一个小问题:java bean 组件模型与CORBA 组件模型有什么区别?
- 如何让一个showMessageDialog现实10秒后自动关闭呢?
- 关于鼠标事件的小问题!!!
object.This code stores a reference to an externally mutable
object into the internal representation of the object.If instances
are accessed by untrusted code,and unchecked changes to the mutable object would compromise security or other important properties,you will need to do something different.
Storing a copy of the object is better approach in many situations.可能因使引用可指向多个对象而暴露内部存储结构。
这代码使一个指向外部多个对象的引用指向了一个内部对象存储地址。
如果实例被未被信任代码访问或多个对象发生了未经检查的改变就会危及安全性或其它重要属性,
你需要去做一些不同的事情。存储一个对象的拷贝在许多情况下会是一个更好的方法。
(翻译若有不对之处请多包涵^^)
为什么要放到一个临时变量中就可以了?
public class Test {
private String[] name; public String[] getName() {
String[] temp = name;
return temp;
} public void setName(String[] name) {
String[] temp = name;
this.name = temp;
}
}
String[] temp = name; 他会检测你做了一些事情,但实际上啥也没做!
2、所有容器类型如ArrayList和数组类型,如果你都自动生成get set,都会有这个警告。
3、这个警告的主要目的是:一般的get set直接把此对象中某一容器的引用放到外部,可以随便更改,违反了封装的原则,至于那个temp的方法,由于不是直接对内部容器进行操作,故没有警告,但没有实际意义,自己知道即可。