日期:2014-05-16  浏览次数:20370 次

eclipse插件FindBugs各种bug描述及解决方法

1 )原代码如下:

protected String[] a = null;

public void test(String[] str){

??? this.a = str;

}

findbugs描述为:

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 void test(String[] str){

?

??? if(str!=null)

??? this.a =?str.clone();

}

--------------------------------------------

2 )在bean中定义数组类型的bug

[参考]http://topic.csdn.net/u/20080115/20/c8893ce0-5546-4762-97bb-9b00d10885cc.html

原代码:

private String[] name;?

public String[] getName() {?
return name;?
}?

public void setName(String[] name) {?
this.name = name;?
}