《Findbugs缺陷等级对照表.doc》由会员分享,可在线阅读,更多相关《Findbugs缺陷等级对照表.doc(24页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-作者xxxx-日期xxxxFindbugs缺陷等级对照表【精品文档】FindBugs Bug DescriptionsThis document lists the standard bug patterns reported by version .Summary序号等级DescriptionCategory14AEC: Call to equals() with null argument调用Equal方法的参数为空Correctness15AEC: Call to equals() comparing different interface types 调用Equal方法去比较不同的接
2、口类型Correctness16AEC: Call to equals() comparing different types调用Equal方法去比较不同的数据类型Correctness17AES: Comparison of String objects using = or !=使用= 或者 != 去比较字符串或对象Correctness29BIJU: TestCase implements setUp but doesnt call super.setUp()测试实例实现了setUp()但没有调用super.setUp()Correctness36ANP: Null pointer de
3、reference in method方法中存在空指针Correctness37ANP: Null pointer dereference in method on exception path方法中存在某异常路径中的空指针Correctness38ANP: Possible null pointer dereference in method方法中存在可能在运行时出现的空指针异常Correctness39ANP: Possible null pointer dereference in method on exception path方法中存在可能在某些异常路径下出现的空指针异常Correc
4、tness41CNm: Class defines equal(); should it be equals()?类中定义了,这也有可能是有意这么做的Correctness42BNm: Confusing method names一些方法名只有大小写的区别,容易混绕Correctness43BNm: Confusing method name方法名和其超类的类名相同Correctness44CNm: Class defines hashcode(); should it be hashCode()?类中定义了hashCode()方法,但是没有重写中的hashCode()方法,这也有可能是有意这
5、么做的Correctness45CNm: Class defines tostring(); should it be toString()?类中定义了tostring()方法,但是没有重写中的tostring()方法,这也有可能是有意这么做的Correctness46ANm: Very confusing method names一些方法名只有大小写的区别,特别容易混绕Correctness47AODR: Method may fail to close database resource方法可能没有关闭数据源Correctness48AODR: Method may fail to clo
6、se database resource on exception方法在异常时可能无法关闭数据源Correctness49AOS: Method may fail to close stream方法可能没有关闭流Correctness50AOS: Method may fail to close stream on exception方法在异常时可能无法关闭流Correctness53CRCN: Redundant comparision to null of previously checked value预测值的几个比较的值中有null值Correctness54CRCN: Redunda
7、nt comparison to null几个比较的值中有null值Correctness57CRV: Method ignores return value方法忽略了返回值Correctness59ASI: Static initializer for class creates instance before all static final fields assigned类的静态初始化器实例化一个该类对象要在所有的常量属性定义之前Correctness72CUwF: Unwritten field永远不会写到的字段,所有读取将返回默认值Correctness83AMS: Field is
8、nt final but should be字段应该为常量的却不是常量Malicious code vulnerability86AIS2: Inconsistent synchronization类中字段访问不同步Multithreaded correctness88AML: Method synchronizes on an updated field方法从一个可变字段对象的引用中同步。这是不太可能有用的,因为不同的线程可以在不同的对象上同步。Multithreaded correctness92CRu: Invokes run on a thread (did you mean to s
9、tart it instead?)当一个类继承Runnable接口时候,还去调用run方法,实际上只需要调用Start方法就可以启动新的线程,Multithreaded correctness93CSC: Constructor invokes Thread.start()构造函数调用Thread.start()Multithreaded correctness102CDm: Method invokes dubious new String(String) constructor; just use the argument方法中调用String的构造函数来新建一个字符串,直接使用其参数即可
10、Performance103ADm: Method invokes dubious String.equals(); use String.length() = 0 instead方法中调用了不确定的String.equals(),使用String.length() = 0来代替Performance104ADm: Method invokes toString() method on a String; just use the String方法中用一个字符串去调用方法toString(),用String就可以了Performance105CDm: Method invokes dubiou
11、s new String() constructor; just use 方法中新建一个空字符串用new String()。直接用“”就可以了Performance106CFI: Empty finalizer should be deleted空finalizer()方法是没有用的,所以应该予以删除Performance114CUPM: Private method is never called这个私有方法从来没有被调用到Performance115CUrF: Unread field读不到的字段,应该从类中删除Performance116CUuF: Unused field读不到的字段,
12、应该从类中删除PerformanceDescriptionsAM: Creates an empty jar file entryThe code calls putNextEntry(), immediately followed by a call to closeEntry(). This results in an empty JarFile entry. The contents of the entry should be written to the JarFile between the calls to putNextEntry() and closeEntry().AM:
13、Creates an empty zip file entryThe code calls putNextEntry(), immediately followed by a call to closeEntry(). This results in an empty ZipFile entry. The contents of the entry should be written to the ZipFile between the calls to putNextEntry() and closeEntry().BIT: Incompatible bit masksThis method
14、 compares an expression of the form (a & C) to D, which will always compare unequal due to the specific values of constants C and D. This may indicate a logic error or typo.BIT: Incompatible bit masksThis method compares an expression of the form (a & 0) to 0, which will always compare equal. This m
15、ay indicate a logic error or typo.BIT: Incompatible bit masksThis method compares an expression of the form (a | C) to D. which will always compare unequal due to the specific values of constants C and D. This may indicate a logic error or typo.Typically, this bug occurs because the code wants to pe
16、rform a membership test in a bit set, but uses the bitwise OR operator (|) instead of bitwise AND (&).BOA: Class overrides a method implemented in super class Adapter wronglyThis method overrides a method found in a parent class, where that class is an Adapter that implements a listener defined in t
17、he java.awt.event or javax.swing.event package. As a result, this method will not get called when the event occurs.BRSA: Method attempts to access a result set field with index 0A call to getXXX or updateXXX methods of a result set was made where the field index is 0. As ResultSet fields start at in
18、dex 1, this is always a mistake.CN: Class implements Cloneable but does not define or use clone methodClass implements Cloneable but does not define or use the clone method.CN: clone method does not call super.clone()This class defines a clone() method that does not call super.clone(), and is not fi
19、nal. If this class (A) is extended by a subclass (B), and the subclass B calls super.clone(), then it is likely that Bs clone() method will return an object of type A, which violates the standard contract for clone().If all clone() methods call super.clone(), then they are guaranteed to use Object.c
20、lone(), which always returns an object of the correct type.Co: Covariant compareTo() method definedThis class defines a covariant version of compareTo(). To correctly override the compareTo() method in the Comparable interface, the parameter of compareTo() must have type .DE: Method might drop excep
21、tionThis method might drop an exception. In general, exceptions should be handled or reported in some way, or they should be thrown out of the method.DE: Method might ignore exceptionThis method might ignore an exception. In general, exceptions should be handled or reported in some way, or they shou
22、ld be thrown out of the method.Dm: Method invokes System.exit(.)Invoking System.exit shuts down the entire Java virtual machine. This should only been done when it is appropriate. Such calls make it hard or impossible for your code to be invoked by other code. Consider throwing a RuntimeException in
23、stead.EC: Call to equals() with null argumentThis method calls equals(Object), passing a null value as the argument. According to the contract of the equals() method, this call should always return false.EC: Call to equals() comparing different interface typesThis method calls equals(Object) on two
24、references of unrelated interface types (neither is a subtype of the other). According to the contract of equals(), objects of different classes should always compare as unequal. Note that it is possible that the program contains classes that implement both interfaces, so the comparison may be valid
25、. However, it is worth inspecting closely.EC: Call to equals() comparing different typesThis method calls equals(Object) on two references of different types. According to the contract of equals(), objects of different classes should always compare as unequal; therefore, it is likely that the result
26、 of this comparision will always be false at runtime.ES: Comparison of String objects using = or !=This code compares 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 sam
27、e string value may be represented by two different String objects. Consider using the equals(Object) method instead.Eq: Covariant equals() method definedThis class defines a covariant version of equals(). To correctly override the equals() method in , the parameter of equals() must have type .Eq: Co
28、variant equals() method defined, Object.equals(Object) inheritedThis class defines a covariant version of the equals() method, but calls the normal equals(Object) method defined in the base class. The class should probably define a non-covariant version of equals(). (I.e., a method with the signatur
29、e boolean equals(java.lang.Object).FI: Explicit invocation of finalizerThis method contains an explicit invocation of the finalize() method on an object. Because finalizer methods are supposed to be executed once, and only by the VM, this is a bad idea.FI: Finalizer does not call superclass finalize
30、rThis finalize() method does not make a call to its superclasss finalize() method. So, any finalizer actions defined for the superclass will not be performed. Add a call to super.finalize().FI: Finalizer nullifies superclass finalizerThis empty finalize() method explicitly negates the effect of any
31、finalizer defined by its superclass. Any finalizer actions defined for the superclass will not be performed. Unless this is intended, delete this method.HE: Class defines equals() but not hashCode()This class overrides equals(Object), but does not override hashCode(). Therefore, the class may violat
32、e the invariant that equal objects must have equal hashcodes.HE: Class defines equals() and uses Object.hashCode()This class overrides equals(Object), but does not override hashCode(), and inherits the implementation of hashCode() from (which returns the identity hash code, an arbitrary value assign
33、ed to the object by the VM). Therefore, the class is very likely to violate the invariant that equal objects must have equal hashcodes.If you dont want to define a hashCode method, and/or dont believe the object will ever be put into a HashMap/Hashtable, define the hashCode() method to throw Unsuppo
34、rtedOperationException.HE: Class defines hashCode() but not equals()This class defines a hashCode() method but not an equals() method. Therefore, the class may violate the invariant that equal objects must have equal hashcodes.HE: Class defines hashCode() and uses Object.equals()This class defines a
35、 hashCode() method but inherits its equals() method from (which defines equality by comparing object references). Although this will probably satisfy the contract that equal objects must have equal hashcodes, it is probably not what was intended by overriding the hashCode() method. (Overriding hashC
36、ode() implies that the objects identity is based on criteria more complicated than simple reference equality.)HE: Class inherits equals() and uses Object.hashCode()This class inherits equals(Object) from an abstract superclass, and hashCode() from from (which returns the identity hash code, an arbit
37、rary value assigned to the object by the VM). Therefore, the class is very likely to violate the invariant that equal objects must have equal hashcodes.If you dont want to define a hashCode method, and/or dont believe the object will ever be put into a HashMap/Hashtable, define the hashCode() method
38、 to throw UnsupportedOperationException.IC: Initialization circularityA circularity was detected in the static initializers of the two classes referenced by the bug instance. Many kinds of unexpected behavior may arise from such circularity.IJU: TestCase implements setUp but doesnt call super.setUp(
39、)Class is a JUnit TestCase and implements the setUp method. The setUp method should call super.setUp(), but doesnt.IMSE: Dubious catching of IllegalMonitorStateExceptionIllegalMonitorStateException is generally only thrown in case of a design flaw in your code (calling wait or notify on an object yo
40、u do not hold a lock on).It: Iterator next() method cant throw NoSuchElement exceptionThis class implements the interface. However, its next() method is not capable of throwing . The next() method should be changed so it throws NoSuchElementException if is called when there are no more elements to r
41、eturn.MF: Class defines field that obscures a superclass fieldThis class defines a field with the same name as a visible instance field in a superclass. This is confusing, and may indicate an error if methods update or access one of the fields when they wanted the other.MF: Method defines a variable
42、 that obscures a fieldThis method defines a local variable with the same name as a field in this class or a superclass. This may cause the method to read an uninitialized value from the field, leave the field uninitialized, or both.MWN: Mismatched notify()This method calls Object.notify() or Object.
43、notifyAll() without obviously holding a lock on the object. Calling notify() or notifyAll() without a lock held will result in an IllegalMonitorStateException being thrown.MWN: Mismatched wait()This method calls Object.wait() without obviously holding a lock on the object. Calling wait() without a l
44、ock held will result in an IllegalMonitorStateException being thrown.NP: Null pointer dereference in methodA null pointer is dereferenced here. This will lead to a NullPointerException when the code is executed.NP: Null pointer dereference in method on exception pathA pointer which is null on an exc
45、eption path is dereferenced here. This will lead to a NullPointerException when the code is executed. Note that because FindBugs currently does not prune infeasible exception paths, this may be a false warning.Also note that FindBugs considers the default case of a switch statement to be an exceptio
46、n path, since the default case is often infeasible.NP: Possible null pointer dereference in methodA reference value dereferenced here might be null at runtime. This may lead to a NullPointerException when the code is executed.NP: Possible null pointer dereference in method on exception pathA referen
47、ce value which is null on some exception control path is dereferenced here. This may lead to a NullPointerException when the code is executed. Note that because FindBugs currently does not prune infeasible exception paths, this may be a false warning.Also note that FindBugs considers the default case of a switch statement to be an exception path, since the default case is often infeasible.NS: Questionable use of non-short-circuit logicThis code seems to be using non-short