1.Call to equals() comparing different type 2.Class doesn't override equals in superclass 一般就是重写equals(obj)即可 即public boolean equals(Object obj){ return super.equals(obj);} serialVersionUID 用来表明类的不同版本间的兼容性 简单来说,Java的序列化机制是通过在运行时判断类的serialVersionUID来验证版本一致性的。在进行反序列化时,JVM会把传来的字节流中的serialVersionUID与本地 相应实体(类)的serialVersionUID进行比较,如果相同就认为是一致的,可以进行反序列化,否则就会出现序列化版本不一致的异常。 当实现java.io.Serializable接口的实体(类)没有显式地定义一个名为serialVersionUID,类型为long的变量时,Java序列化机制会根据编译的class自动生成一个 serialVersionUID作序列化版本比较用,这种情况下,只有同一次编译生成的class才会生成相同的serialVersionUID 。 如果我们不希望通过编译来强制划分软件版本,即实现序列化接口的实体能够兼容先前版本,未作更改的类,就需要显式地定义一个名为serialVersionUID,类型为long 的变量,不修改这个变量值的序列化实体都可以相互进行串行化和反串行化。 也就是这个错误 你要定义一个名为 serialVersionUID,类型为long的变量 按照新版Eclipse自动填写规则 就是: 4.Class names shouldn't shadow simple name of superclass 5.Comparison of String parameter using == or != 原因:当比较两个字符串内容是否相同时,仅当两个字符串在源文件中都是常量时或者是使用intern()来比较才可以用==来比较,否则最好使用对象比较方法equal。附 string比较: String str1 = "java"; String str2 = "java"; System.out.print(str1==str2); 结果:true(二者都为常量) String str1 = new String("java"); String str2 = new String("java"); System.out.print(str1==str2); 结果:false(二者为对象) String str1 = "java"; String str2 = "blog"; String s = str1+str2; System.out.print(s=="javablog"); 结果:false(s不为常量,为对象) String s1 = "java"; String s2 = new String("java"); System.out.print(s1.intern()==s2.intern()); 结果:true(但是intern()方法在效率和实现方式上不统一) 6.Call to equals() comparing different types 7.Equals checks for noncompatible operand 8.equals method always returns false 9.equals() method does not check for null argument 一般人都会这样写代码: 12.Can't close pw since it is always null 13.Non-transient non-serializable instance field in serializable class 14.May expose internal representation by incorporating reference to mutable object JAVA里,对象是引用传递的,setObj的时候,对象不要直接赋值(this.regDate = regDate),可改为:this.regDate = (Date)regDate.clone();, 15.Method names should start with a lower case letter 16.Uninitialized read of field in constructor 17.Method concatenates strings using + in a loop The method seems to be building a String using concatenation in a loop. In each iteration, the String is converted to a StringBuffer/StringBuilder, appended to, and converted back to a String. This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration. Better performance can be obtained by using a StringBuffer (or StringBuilder in Java 1.5) explicitly. For example: // This is bad String s = ""; for (int i = 0; i < field.length; ++i) { s = s + field[i]; } // This is better StringBuffer buf = new StringBuffer(); for (int i = 0; i < field.length; ++i) { buf.append(field[i]); } String s = buf.toString(); |
等待继续更新。。。。。。。。 |
相关资料: 1:hyddd的FindBugs分析记录 http://www.cnblogs.com/hyddd/tag/hyddd%E7%9A%84FindBugs%E5%88%86%E6%9E%90%E8%AE%B0%E5%BD%95/
2:FindBugs Bug Detector Report
http://www.jquantlib.org/sites/jquantlib/findbugs.html
3:FindBugs Bug Descriptions (推荐)
http://findbugs.sourceforge.net/bugDescriptions.html#NP_NULL_PARAM_DEREF 4.FindBugs缺陷类型统计分析: http://donsun.javaeye.com/blog/697407 |