日期:2014-05-16 浏览次数:20532 次
findbugs 出错类型及对应解释
1、Dead store to local variable 本地变量存储了闲置不用的对象
举例:
List accountCoList = new ArrayList();
我们为accountCoList新建了一个对象,但是程序的后面并没有使用这个这个新建对象。
建议改为:
List accountCoList = null;
2、Write to static field from instance method 向static字段中写入值
举例:
?private static DBRBO dbrBO;
?public final void refresh() {
????????danskeBankBO = null;
????????dbrBO = null;
????????fileAndPathBO = null;
????}
建议改为:
去掉static。
3、Load of known null value 大体意思是加载了null的对象。
举例
????????if (null == boList) {
????????????for (int i = 0; i < boList.size(); i++) {
????????????????entityList.add(productBOToEntity(boList.get(i)));
????????????}
????????}
4、Exception is caught when Exception is not thrown 这个意思比较好理解:就是catch了异常但是try里并没有抛出异常
5、Method ignores exceptional return value 没有对方法的异常返回值进行检查
6、Comparison of String objects using == or !=
This code compares java.lang.String objects for reference equality using the == or != operators.
Unless both strings are either constants in a source file, or have been interned using the String.intern() method,
?the same string value may be represented by two different String objects. Consider using the equals(Object) method
??instead.
??从字面意思可以理解String对象进行比较的时候:只有两种情况可以使用== or !=的,这两种情况是;在源文件中是个常数或者是调用
??String.intern()方法,使用String的规范化表示形式来进行比较,如果不是这两中情况的话推荐使用.equals(object)方式
7、Method names should start with a lower case letter 这个好理解 方法名的第一个字母不能是大写
8、Non-transient non-serializable instance field in serializable class
This Serializable class defines a non-primitive instance field which is neither transient, Serializable,
?or java.lang.Object, and does not appear to implement the Externalizable interface or the readObject()
??and writeObject() methods.? Objects of this class will not be deserialized correctly if a non-Serializable object
???is stored in this field.
这个错误的意思是:在可序列化的类中存在不能序列化或者不能暂存的数据