-
FindBug
错误修改中文说明大全
复制你的
Pattern id
p>
然后用
Ctrl+F
快速查找定位
Security
关于代码安全性防护
序号
1.
Description
Dm:
Hardcoded constant database password
(DMI_CONSTANT_DB_PASSWORD)
代
码中创建
DB
的密码时采用了写死的密码。
2.
备注
Dm: Empty database password
(DMI_EMPTY_DB_PASSWORD)
创建数据
库连接时没有为数据库设置密码,
这会使数据库没有必
要的保护
。
3.
HRS: HTTP cookie formed from untrusted
input
(HRS_REQUEST_PARAMETER_TO_COOKIE)
此代码使用不受信任的
HTTP
参数构
造一个
HTTP Cookie
。
4.
HRS: HTTP Response splitting
vulnerability
(HRS_REQUEST_PARAMETER_TO_HTTP_HEADER)
在代码中直接把一个
HTTP
的参数写
入一个
HTTP
头文件中,
它
为
HTTP
的响应暴露了漏洞。
5.
SQL: Nonconstant string
passed to execute method on an
SQL
statement
(SQL_NONCONSTANT_STRING_PASSE
D_TO_EXECUTE)
该方法以字符串的形式来调用
S
QLstatement
的
execute
方法,
它似乎是动态生成
SQL
语
句的方法。
这会更容易受到
SQL
注入
攻击。
6.
XSS: JSP reflected cross
site scripting vulnerability
(XSS_REQUEST_PARAMETER_TO_JSP_WRITER) <
/p>
在代码中在
JSP
输出中直接写入一个<
/p>
HTTP
参数,这会造成一
个跨站点的脚
本漏洞。
Experimental
序号
Description
备注
1.
LG: Potential lost logger
changes due to weak
reference in
OpenJDK
(LG_LOST_LOGGER_DUE_TO_WEAK_REFERENCE)
OpenJDK
的引入了一种潜在的不兼容问题,特别是,
p>
的行为改变时。它现在使用
内部弱引用,而
不是强引用。–
logger
配置改变,它就
< br>是丢失对
logger
的引用,这本是一个合理的变化,
但
不幸的是一些代码对旧的行为有依赖关系。这意味着,
当进行
垃圾收集时对
logger
配置将会丢失。例如:
public static void initLogging()
throws Exception {
Logger
logger =
ger(
dler(new FileHandler()); // call to
change logger configuration
ParentHandlers(false); // another
call to change logger configuration
}
该方法结束时
logger
的引用就丢失了,如果你刚刚结
束调用
ini
tLogging
方法后进行垃圾回收,
logger
的
配置将会丢失(因为只有保持记录器弱引用)。
public static void main(String[] args)
throws
Exception {
initLogging(); // adds a file handler
to the logger
(); // logger
configuration lost
ger(
message
expected
}
2.
OBL: Method may fail to
clean up stream or
resource
(OBL_UNSATISFIED_OBLIGATION)
这种方法可能无法清除
(关闭,处置)一个流,数据库
对象,或其他资源需要一个明确的清理行动。
一般来说,如果一个方法打开一个流或其他资源,该方
< br>法应该使用
try / finally
块来确保在方法
返回之前流或
资源已经被清除了。这种错误模式基本上和
OS_
OPEN_STREAM
和
ODR_OPEN_DATABAS
E_RESOURCE
错误模式相同,
但是是在不同在静态分析
技术。
我们正为这个错误模式
的效用收集反馈意见。
Bad
practice
代码实现中的一些坏习惯
序
号
1.
AM: Creates an empty jar file entry
(AM_CREATES_EMPTY_JAR_FILE_ENTRY)
调用
putNextEntry()
方法写入新的
jar
文件条目时立即调用
closeEntry()
方法。这样会造成
JarFile
条目为空。
2.
AM: Creates an empty zip file entry
(AM_CREATES_EMPTY_ZIP_FILE_ENTRY)
调用
putNextEntry()
方法写入新的
zip
文件条目时立即调用
closeEntry()
方法。这样会造成
ZipFile
条目为空。
3.
BC: Equals method should not assume
anything about the
Description
备
注
type of its argument
(BC_EQU
ALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS)
equals(Object o)
方法不能对参数
o
的类型做任何的假设。比较此
对象与指定的对象
。当且仅当该参数不为
null
,并
且是表示与此对
象相同的类型的对象时,结果才为
true
。
4.
BC: Random object created and used only
once
(DMI_RANDOM_USED_ONLY_ONCE)
随机创建对象只使用过一次就抛弃
5.
BIT: Check for sign of
bitwise operation (BIT_SIGNED_CHECK)
检查位操作符运行是否合理
(( &
ED) > 0)
If ED is a negative number,
this is a candidate for a
bug. Even
when ED is not negative, it seems good
practice to use '!= 0' instead of '>
0'.
6.
CN: Class implements Cloneable but does
not define or use
clone method
(CN_IDIOM)
按照惯例,
实现此接口的类应该使用公
共方法重写
(它
是受保护的),以获得有关重写此方法的详细信息。此接口不
包含
clone
< br>方法。
因此,
因为某个对象实现了此接口就克隆它是不可
能的
,
应该实现此接口的类应该使用公共方法重写
7.
CN: clone
method does not call ()
(CN_IDIOM_NO_SUPER_CALL)
一个非
final
类型的类定义了
clone
()
方法而没有调用
()
方法。例如:
B
扩展自
A
,
如果
B
中
clone
< br>方法调用了
(),而
A
中的
clone
没有调用
()
,就会造成结果类型
不准确。要求
A
的
clone
方法中调用
()
方法。
8.
CN: Class defines clone() but doesn't
implement Cloneable
(CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE)
类中定义了
clone
方法但是它没有
实现
Cloneable
接口
9.
Co: Abstract class defines covariant
compareTo() method
(CO_ABSTRACT_SELF) <
/p>
抽象类中定义了多个
compareTo()
方法,
正确的是覆写
Comparable
中的
compareTo
方法,方法的参数为
Object
类型,如下例:
int compareTo(T o)
比较此对象与指定对象的顺序。
10.
Co: Covariant compareTo() method
defined
LF_NO_OBJECT)
类中定义了多个
compareTo()
方法,正确的是覆写
Comp
arable
中
的
compareTo
方法,方法的参数为
Object
类型
11.
DE: Method might drop
exception (DE_MIGHT_DROP)
方法可能抛出异常
12.
DE: Method might ignore exception
(DE_MIGHT_IGNORE)
方法可能忽略异常
13.
DMI: Don't use removeAll to clear a
collection
(DMI_USING_REMOVEALL_TO_CLEA
R_COLLECTION)
不要用
removeAll
p>
方法去
clear
一个集合
14.
DP: Classloaders should
only be created inside doPrivileged
block
(DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED)
类加载器只能建立在特殊的方法体内
15.
Dm: Method invokes (...) (DM_EXIT)
在方法中调用
(...)
语句,
考虑用
RuntimeException
来代
替
16.
Dm: Method invokes dangerous method
runFinalizersOnExit
(DM_RUN_FINALIZERS_ON_EXIT)
在方法中调用了
alizersOnExit
或者
alizersOnExit
方法,因为这样做是
很危险的。
17.
ES: Comparison of String
parameter using == or !=
(ES_COMPARING_PARAMETER_STRING_WITH_EQ)
用
==
或者
!
=
方法去比较
String
类型的参数
18.
ES: Comparison of String
objects using == or !=
(ES_COMPARING_STRINGS_WITH_EQ)
< br>用
==
或者!
=
去比较
String
类型的对象
19.
Eq: Abstract class defines
covariant equals() method
(EQ_ABSTRACT_SELF)
20.
Eq: Equals checks for noncompatible
operand
(EQ_CHECK_FOR_OPERAND_NOT_COMPA
TIBLE_WITH_THIS)
equals
方法检查不
一致的操作。两个类根本就是父子关系而去调用
equals
方法去判读对象是否相等。
public boolean equals(Object o) {
if (o
instanceof Foo)
return
(((Foo)o).name);
else if (o instanceof String)
return (o);
else return false;
21.
Eq: Class defines compareTo(...) and
uses ()
(EQ_COMPARETO_USE_OBJECT_EQUALS)
类中定义了
compareTo
方法但是继承了
p>
Object
中的
compareTo
p>
方法
22.
Eq: equals method fails for
subtypes
(EQ_GETCLASS_AND_CLASS_CONSTANT)
类中的
equals
方法可能被子类中的方法所破坏
,当使用类似于
==
ss()
的判断时考虑用
ss() ==
ss()
来替换
23.
Eq: Covariant equals() method defined
(EQ_SELF_NO_OBJECT)
类中定义了多个
e
quals
方法。
正确的做法是覆写
O
bject
中的
equals
方法,它
的参数为
Object
类型的对象。
24.
FI: Empty finalizer should be deleted
(FI_EMPTY)
为空的
finalizer
方法应该删除。一下关于
finalizer
的内
容省略
25.
GC: Unchecked type in generic call
(GC_UNCHECKED_TYPE_IN_GENERIC_CALL)
This call to a generic collection
method passes an argument
while compile
type Object where a specific type from the
generic type parameters is expected.
Thus, neither the
standard Java type
system nor static analysis can provide
useful information on whether the
object being passed as a
parameter is
of an appropriate type.
26.
HE: Class defines equals() but not
hashCode()
(HE_EQUALS_NO_HASHCODE)
方法定义了
equals
方法却没有定义
hashCode
方法
27.
HE: Class defines hashCode() but not
equals()
(HE_HASHCODE_NO_EQUALS)
类定义了
hashCode
方法去没有定义
equal
方法
28.
HE: Class defines equals()
and uses de()
(HE_EQUALS_USE_HASHCODE)
一个类覆写了
equals
方法,
p>
没有覆写
hashCode
方法,
使用了
Object
对象的
hashCode
方法
29.
HE: Class inherits equals() and uses
de()
(HE_INHERITS_EQUALS_USE_HASHCODE)
子类继承了父类的
equals
方法却
使用了
Object
的
hashCod
e
方法
30.
IC: Superclass uses subclass during
initialization
(IC_SUPERCLASS_USES_SUBC
LASS_DURING_INITIALIZATION)
子类在父类未初始化之前使用父类对象实例
public class
CircularClassInitialization {
static class InnerClassSingleton
extends
CircularClassInitialization {
static
InnerClassSingleton singleton = new
InnerClassSingleton();
}
static CircularClassInitialization foo
=
ton;
}
31.
IMSE: Dubious catching of
IllegalMonitorStateException
(IMSE_DONT_CATCH_IMSE)
捕捉违法的
监控状态异常,例如当没有获取到对象锁时使用其
wait
和<
/p>
notify
方法
32.
ISC: Needless instantiation of class
that only supplies static
methods
(ISC_INSTANTIATE_STATIC_CLASS)
为使用静态方法而
创建一个实例对象。
调用静态方法时只需要使用类
名
+
静态方法名就可以了。
33.
It: Iterator next() method can't throw
NoSuchElementException
(IT_NO_SUCH_ELEMENT)
迭代器的
nex
t
方法不能够抛出
NoSuchElementExcepti
on
34.
J2EE: Store of non
serializable object into HttpSession
(J
2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION)
在
HttpSession
对象中保存
非连续的对象
35.
JCIP: Fields of immutable classes
should be final
(JCIP_FIELD_ISNT_FINAL_
IN_IMMUTABLE_CLASS)
The
class is annotated with ble,
and the
rules for that annotation require that all fields
are
final. .
36.
NP: Method with Boolean return type
returns explicit null
(NP_BOOLEAN_RETURN_NULL)
返回值
为
boolean
类型的方法直接返回
null
,这样会导致空指针异
常
37.
NP: equals() method does not check for
null argument
(NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT)
变量调用
equals
方法时没有进行
是否为
null
的判断
38.
NP: toString method may return null
(NP_TOSTRING_COULD_RETURN_NULL)
toString
方法可能返回
null
39.
Nm: Class names should start with an
upper case letter
(NM_CLASS_NAMING_CONVENTION)
类的名称以大写字母名称开头
40.
Nm: Class is not derived from an
Exception, even though it is
named as
such (NM_CLASS_NOT_EXCEPTION)
类的名称中含有
p>
Exception
但是却不是一个异常类的子类,
这种名称
会造成混淆
41.
Nm: Confusing method names
(NM_CONFUSING)
令人迷惑的方面命名
42.
Nm: Field names should start with a
lower case letter
(NM_FIELD_NAMING_CONVENTION)
非
final
类型的字段需要遵循驼峰命名原则
43.
Nm: Use of identifier that
is a keyword in later versions of Java
(NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER)
验证是否是
java
预留关键字
44.
Nm: Use of identifier that is a keyword
in later versions of Java
(NM_FUTURE_KE
YWORD_USED_AS_MEMBER_IDENTIFIER)
验证是否时<
/p>
java
中的关键字
45.
Nm: Method names should start with a
lower case letter
(NM_METHOD_NAMING_CONVENTION)
方法名称以小写字母开头
46.
Nm: Class names shouldn't shadow simple
name of
implemented interface
(NM_SAME_SIMPLE_NAME_AS_INTERFACE)
实现同一接口实现类不能使用相同的名称,
即使它们位于不同的包中
p>
47.
Nm: Class names shouldn't
shadow simple name of superclass
(NM_SAME_SIMPLE_NAME_AS_SUPERCLASS)
继承同一父类的子类不能使用相同的名称,
即使它们位于不同的包中<
/p>
48.
Nm: Very confusing method
names (but perhaps intentional)
(NM_VERY_CONFUSING_INTENTIONAL)
很容易混淆的方法命名,
例如方法的名称名称使用使用大小写来区别
两个不同的方法。
49.
Nm: Method doesn't override method in
superclass due to
wrong package for
parameter
(NM_WRONG_PACKAGE_INTENTIONAL)
< br>由于错误引用了不同包中相同类名的对象而不能够正确的覆写父类
中的方法
import
public
class A {
public int f(Foo x) { return 17; }
}
import
public class B extends A {
public int f(Foo x) {
return 42; }
public int f( x) { return 27; }
}
50.
ODR: Method may fail to
close database resource
(ODR_OPEN_DATABASE_RESOURCE)
方法中可能存在关闭数据连接失败的情况
51.
OS: Method may fail to close stream
(OS_OPEN_STREAM)
方法中可能存在关闭流失败的情况
52.
OS: Method may fail to close stream on
exception
(OS_OPEN_STREAM_EXCEPTION_PATH)
方法中可能存在关闭流时出现异常情况
53.
RC: Suspicious reference comparison to
constant
(RC_REF_COMPARISON_BAD_PRACTICE)
当两者为不同类型的对象时使用
equals
方法来
比较它们的值是否相
等,而不是使用
==
方法。例如比较的两者为
r,
54.
RC: Suspicious reference comparison of
Boolean values
(RC_REF_COMPARISON_BAD_P
RACTICE_BOOLEAN)
使用
==
或者
!=
操作符来比较两个
Boolean
类型的对象,
建议使用
equals
方法。
55.
RR: Method ignores results of ()
(RR_NOT_CHECKED)
方法忽略返回的多个字符,如果对结果没有检查
就没法正确处理用户读取少量字符请求的
情况。
56.
RR: Method ignores results of ()
(SR_NOT_CHECKED)
()
方法忽略返回的多个字符,如果对结果没有检查
就没法正确处理用户跳过少量字符请
求的情况
57.
RV: Method ignores exceptional return
value
(RV_RETURN_VALUE_IGNORED_BAD_PRACTICE)
方法忽略返回值的异常信息
58.
SI: Static initializer creates instance
before all static final fields
assigned
(SI_INSTANCE_BEFORE_FINALS_ASSIGNED)
在所有的
static final
字
段赋值之前去使用静态初始化的方法创建一
个类的实例。
59.
Se: Non-serializable value stored into
instance field of a
serializable class
(SE_BAD_FIELD_STORE)
非序列化的值保存在声明为序列化的的非序列化字段中
60.
Se: Comparator doesn't implement
Serializable
(SE_COMPARATOR_SHOULD_BE_SERIALIZABLE)
Comparator
接口没有实现
S
erializable
接口
61.
Se: Serializable inner class
(SE_INNER_CLASS)
序列化内部类
62.
Se: serialVersionUID isn't final
(SE_NONFINAL_SERIALVERSIONID)
关于
UID
类的检查内容省略
63.
Se: Class is Serializable but its
superclass doesn't define a void
constructor
(SE_NO_SUITABLE_CONSTRUCTOR)
子类序列化时父类没有
提供一个
void
的构造函数
64.
Se: Class is Externalizable but doesn't
define a void constructor
(SE_NO_SUITAB
LE_CONSTRUCTOR_FOR_EXTERNALIZATION)
Externalizable
实例类没有定义一个
void
类型的构造函数
65.
Se: The readResolve method must be
declared with a return
type of Object.
(SE_READ_RESOLVE_MUST_RETURN_OBJECT)
re
adResolve
从流中读取类的一个实例,此方法必须声明返回一个
Object
类型的对象
66.
Se: Transient field that isn't set by
deserialization.
(SE_TRANSIENT_FIELD_NOT_RESTORED)
This class contains a field that is
updated at multiple places in
the
class, thus it seems to be part of the state of
the class.
However, since the field is
marked as transient and not set in
readObject or readResolve, it will
contain the default value in
any
deserialized instance of the class.
67.
SnVI: Class is Serializable, but
doesn't define serialVersionUID
(SE_NO_SERIALVERSIONID)
一个类实
现了
Serializable
接口但是没有定义
serialVersionUID
类
型的变量。<
/p>
序列化运行时使用一个称为
serialVersionUID
的版本号
与每个可序列化类相关联,
该序列号在反序列化过程中用于验证序列
化对象的发送者和接收者是否为该对象加载了与序列化兼容的类。
如
果接收者加载的该对象的类的
serialVersionUID
与对应的发送者
的类的版本号不同,则反序列化将会导致
In
validClassException
。
可序列化类可以通
过声明名为
的字段(该字段
必须是静态
(static)
、最终
(final)
的
long
型字段)显式声明其自
己的
serialVersionUID
:
ANY-ACCESS-
MODIFIER static final long serialVersionUID =
42L;
68.
UI: Usage of GetResource may be unsafe
if class is extended
(UI_INHERITANCE_UNSAFE_GETRESOURCE)
当一个类被子类继承后不要使用
ss().getResource(
...)
来
获取资源
Cor
rectness
关于代码正确性相关方面的
序
号
1.
BC: Impossible cast
(BC_IMPOSSIBLE_CAST)
不可能的类转换,执行时会抛出
ClassCastException
2.
BC: Impossible downcast
(BC_IMPOSSIBLE_DOWNCAST)
父类在向下进行类型转换时抛出
ClassCastException
3.
BC: Impossible downcast of toArray()
result
(BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY)
集合转换为数组元素时发生的类转换错误。
This code is casting the result of
calling toArray() on a collection
to a
type more specific than Object[], as in:
String[]
getAsArray(Collection
return (String[]) y();
Description
备
注
}
This will usually fail by throwing a
ClassCastException. The
toArray() of
almost all collections return an Object[]. They
can't
really do anything else, since
the Collection object has no
reference
to the declared generic type of the collection.
The correct way to do get
an array of a specific type from a
collection is to use y(new String[]);
or y(new
String[()]); (the latter is
slightly more efficient).
4.
BC: instanceof will always return false
(BC_IMPOSSIBLE_INSTANCEOF)
采
用
instaneof
方法进行比较时总是返回
false
。前提是保证它不是由
于某些逻辑错误造成
的。
5.
BIT: Incompatible bit masks (BIT_AND) <
/p>
错误的使用
&
位操作符,例如
(e & C)
6.
BIT: Check to see if ((...) & 0) == 0
(BIT_AND_ZZ)
检查恒等的逻辑错误
7.
BIT: Incompatible bit masks (BIT_IOR) <
/p>
错误的使用
|
位操作符,例如
(e | C)
8.
BIT: Check for sign of bitwise
operation
(BIT_SIGNED_CHECK_HIGH_BIT)
检查逻辑运算符操作返回的标识。例如
(( &
ED) > 0)
,建议采用
!=0<
/p>
代替
>0
9.
BOA: Class overrides a
method implemented in super class
Adapter wrongly
(BOA_BADLY_OVERRIDDEN_ADAPTER)
子类错误的覆写父
类中用于适配监听其他事件的方法,
从而导致当触发
条件发生时
不能被监听者调用
10.
Bx: Primitive value is
unboxed and coerced for ternary operator
(BX_UNBOXED_AND_COERCED_FOR_TERNARY_OPERATOR) p>
在三元运算符操作时如果没有对值进行封装或者类型转换。例如:
b
?
e1 : e2
11.
DLS: Dead store of class
literal
(DLS_DEAD_STORE_OF_CLASS_LITERAL)
以类的字面名称方式为一个字段赋值后再也没有去使用它,在
1.4jdk
中它会自动调用静态的初始化方法,而在
jdk1.5
中却不会去执行。
12.
DLS: Overwritten increment
(DLS_OVERWRITTEN_INCREMENT)
覆写增量增加错误
i = i++
13.
DMI: Bad constant value for month
(DMI_BAD_MONTH)
hashNext
方法调用
next
方法。
14.
DMI: Collections should not contain
themselves
(DMI_COLLECTIONS_SHOULD_NOT_
CONTAIN_THEMSELVES)
集合没有包含他们自己本身。
15.
DMI: Invocation of hashCode on an array
(DMI_INVOKING_HASHCODE_ON_ARRAY)
数组直接使用
hashCode
方法来返回哈希码。
int [] a1 = new
int[]{1,2,3,4};
n(de());
n(de(a1));
16.
DMI: tsToDouble invoked on an int
(DMI_LONG_BITS_TO_DOUBLE_INVOKED_ON_INT)
17.
DMI: Vacuous call to collections
(DMI_VACUOUS_SELF_COLLECTION_CALL)
集合的调用不能被感知。例如
nsAll(c)
总是返回
true
,而
All(c)<
/p>
的返回值不能被感知。
18.
Dm: Can't use reflection to check for
presence of annotation
without runtime
retention
(DMI_ANNOTATION_IS_NOT_VISIBL
E_TO_REFLECTION)
Unless an annotation
has itself been annotated with
@Retention(E), the annotation can't be
observed using reflection (e.g., by
using the isAnnotationPresent
method).
.
19.
Dm: Useless/vacuous call to EasyMock
method
(DMI_VACUOUS_CALL_TO_EASYMOCK_METHOD)
While ScheduledThreadPoolExecutor
inherits from
ThreadPoolExecutor, a few
of the inherited tuning methods are
not
useful for it. In particular, because it acts as a
fixed-sized pool
using
corePoolSize threads and an unbounded queue,
adjustments to maximumPoolSize have no
useful effect.
20.
EC: equals() used to
compare array and nonarray
(EC_ARRAY_AND_NONARRAY)
数组对象
使用
equals
方法和非数组对象进行比较。即使比较的双方
都
是数组对象也不应该使用
equals
方法,而应该比较它们的内容是否相
等使用
(Object[
], Object[]);
21.
EC: equals(...) used to
compare incompatible arrays
(EC_INCOMPATIBLE_ARRAY_COMPARE)
使用
equls
方法去比较类型不相同的数组。例如:
String[] and
StringBuffer[],
or String[] and int[]
22.
EC: Call to equals() with
null argument (EC_NULL_ARG)
调用
equals
的对象为
null
23.
EC: Call to equals() comparing
unrelated class and interface
(EC_UNRELATED_CLASS_AND_INTERFACE)
使用
equals
方法比较不相关的类和接口<
/p>
24.
EC: Call to equals() comparing
different interface types
(EC_UNRELATED_INTERFACES)
调用
equals
方法比较不同类型的接口
25.
EC: Call to equals() comparing
different types
(EC_UNRELATED_TYPES)
p>
调用
equals
方法比较不同类型的类<
/p>
26.
EC: Using pointer equality to compare
different types
(EC_UNRELATED_TYPES_USI
NG_POINTER_EQUALITY)
This method uses
using pointer equality to compare two
references that seem to be of different
types. The result of this
comparison
will always be false at
runtime
.
27.
Eq: equals method always returns false
(EQ_ALWAYS_FALSE)
使用
equals
p>
方法返回值总是
false
28.
Eq: equals method always returns true
(EQ_ALWAYS_TRUE)
equals
方法返回值总是
true
29.
Eq: equals method compares class names
rather than class
objects (EQ_COMPARING_CLASS_NAMES)
使用
equals
方法去比较一个类的实例和类
的类型
30.
Eq: Covariant equals()
method defined for enum
(EQ_DONT_DEFINE_EQUALS_FOR_ENUM)
This class defines an enumeration, and
equality on enumerations
are defined
using object identity. Defining a covariant equals
method for an enumeration value is
exceptionally bad practice,
since it
would likely result in having two different
enumeration
values that compare as
equals using the covariant enum method,
and as not equal when compared
normally. Don't do it.
31.
Eq: equals()
method defined that doesn't override
equals(Object)
(EQ_OTHER_NO_OBJECT)
类中定义的
equals
方法时不要覆写
p>
equals
(
Object
)方法
32.
Eq: equals() method defined
that doesn't override
(Object)
(EQ_OTHER_USE_OBJECT)
类中定义的
e
quals
方法时不要覆写
Object
中的
equals
(
Object<
/p>
)方
法
33.
Eq: equals method overrides equals in
superclass and may not be
symmetric
(EQ_OVERRIDING_EQUALS_NOT_SYMMETRIC)
34.
Eq: Covariant equals() method defined,
(Object)
inherited (EQ_SELF_USE_OBJECT)
类中定义了一组
equals
方法,<
/p>
但是都是继承的
class
中的
equals(Object)
方法
35.
FE: Doomed test for equality to NaN
(FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER)
This code checks to see if a floating
point value is equal to the
special Not
A Number value (e.g., if (x == )).
However, because of the special
semantics of NaN, no value is
equal to
Nan, including NaN. Thus, x == always
evaluates to false. To check to see if
a value contained in x is the
special
Not A Number value, use (x) (or
(x) if
x is floating point precision).
36.
FS: Format string placeholder
incompatible with passed
argument
(VA_FORMAT_STRING_BAD_ARGUMENT)
错误使用参数类型来格式化字符串
37.
FS: The type of a supplied argument
doesn't match format
specifier
(VA_FORMAT_STRING_BAD_CONVERSION)
指定的格式
字符串和参数类型不匹配,
例如:
(
3
8.
FS: MessageFormat supplied where printf
style format expected
(VA_FORMAT_STRING
_EXPECTED_MESSAGE_FORMAT_SUPPLIED
)
但用
String
的
f
ormat
方法时实际调用了MessageFormat
中干
的格式化方法而引起格式化结果出错。
39.
FS: More arguments are passed than are
actually used in the
format string
(VA_FORMAT_STRING_EXTRA_ARGUMENTS_PASSED) <
/p>
使用
String
的
format
方法时有非法的参数也经过了格式化操作。
40.
FS: Illegal format string
(VA_FORMAT_STRING_ILLEGAL)
格式化
String
对象语句错误
41.
FS: Format string references missing
argument
(VA_FORMAT_STRING_MISSING_ARGUMENT)
String
的
format
操作缺少必要的参数。
42.
FS: No previous argument for format
string
(VA_FORMAT_STRING_NO_PREVIOUS_ARGUMENT)
格式字符串定义错误,例如:
(
抛出<
/p>
MissingFormatArgumentException
异常
43.
GC: No relationship between
generic parameter and method
argument
(GC_UNRELATED_TYPES)
This call to a
generic collection method contains an argument
with an incompatible class from that of
the collection's
parameter (i.e., the
type of the argument is neither a supertype
nor a subtype of the corresponding
generic type argument).
Therefore, it
is unlikely that the collection contains any
objects
that are equal to the method
argument used here. Most likely,
the
wrong value is being passed to the method.
In general, instances of two unrelated
classes are not equal. For
example, if
the Foo and Bar classes are not related by
subtyping,
then an instance of Foo
should not be equal to an instance of
Bar. Among other issues, doing so will
likely result in an equals
method that
is not symmetrical. For example, if you define the
Foo class so that a Foo can be equal to
a String, your equals
method isn't symmetrical since a String
can only be equal to a
String.
In rare cases, people do
define nonsymmetrical equals methods
and still manage to make their code
work. Although none of the
APIs
document or guarantee it, it is typically the case
that if you
check if a
Collection
of argument (e.g., the equals
method of the Foo class) used to
perform the equality checks.
44.
HE: Signature declares use
of unhashable class in hashed
construct
(HE_SIGNATURE_DECLARES_HASHING_OF_UNHAS
HABLE_CLASS
)
A method, field
or class declares a generic signature where a
non-hashable class is used in context
where a hashable class is
required. A
class that declares an equals method but inherits
a
hashCode() method from Object is
unhashable, since it doesn't
fulfill
the requirement that equal objects have equal
hashCodes.
45.
HE: Use of class without a hashCode()
method in a hashed data
structure (HE_USE_OF_UNHASHABLE_CLASS)
A class defines an equals(Object)
method but not a hashCode()
method, and
thus doesn't fulfill the requirement that equal
objects have equal hashCodes. An
instance of this class is used in
a
hash data structure, making the need to fix this
problem of
highest importance.
46.
ICAST: integral value cast to double
and then passed to
(ICAST_INT_CAST_TO_
DOUBLE_PASSED_TO_CEIL)
integral
< br>的值转换为
double
后使用了
方法
47.
ICAST: int value cast to float and then
passed to
(ICAST_INT_CAST_TO_FLOAT_PAS
SED_TO_ROUND)
int
类型的值转换为
float
类型之后调用了
< br>方法
48.
IJU: JUnit assertion in run
method will not be noticed by JUnit
(IJ
U_ASSERT_METHOD_INVOKED_FROM_RUN_METHOD)
在
JUnit
中的断言在
run<
/p>
方法中不会被告知
49.
IJU: TestCase declares a bad suite
method
(IJU_BAD_SUITE_METHOD)
在一个
p>
JUnit
类中声明的一个
suite()
方法必须声明为
public
static suite()
或者
public static ite
suite()
的形式。
50.
IL: A collection is added to itself
(IL_CONTAINER_ADDED_TO_ITSELF)
< br>集合本身作为
add
方法的参数,这样会引起内容溢出。
51.
IL: An apparent infinite loop
(IL_INFINITE_LOOP)
方法的自调用引起的死循环
52.
IM: Integer multiply of result of
integer remainder
(IM_MULTIPLYING_RESULT_OF_IREM)
和整数余数进行乘法运算。
例如:
i
% 60 * 1000
是进行
(i % 60) *
1000
运算而不是
i % (60
* 1000)
53.
INT: Bad comparison of nonnegative
value with negative
constant
(INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE)
保证非负数和负数进行比较
54.
INT: Bad comparison of signed byte
(INT_BAD_COMPARISON_WITH_SIGNED_BYTE)
比较有符合数,要先把有符号数转换为无符合数再进行比较
55.
IO: Doomed attempt to append to an
object output stream
(IO_APPENDING_TO_OBJECT_OUTPUT_STREAM)
宣布试图在对象的输出流处添加元素,
如果你希望能够添加进一
个对象
的输出流中必须保证对象的输出流处于打开状态。
56.
IP: A parameter is dead upon entry to a
method but overwritten
(IP_PARAMETER_IS_DEAD_BUT_OVERWRITTEN)
The initial value of this parameter is
ignored, and the parameter
is
overwritten here. This often indicates a mistaken
belief that the
write to the parameter
will be conveyed back to the caller.
传入
参数的值被忽略,但是对传入值进行了修改,并返回给了调用者
57.
MF: Class defines field that masks a
superclass field
(MF_CLASS_MASKS_FIELD)
子类中定义了和父类中同名的字段。在调用时会出错
58.
MF: Method defines a variable that
obscures a field
(MF_METHOD_MASKS_FIELD)
在方法中
定义的局部变量和类变量或者父类变量同名,
从而引起字段混
淆
。
59.
NP: Null pointer dereference
(NP_ALWAYS_NULL)
对象赋为
null
值后
没有被重新赋值
60.
NP: Null pointer dereference in method
on exception path
(NP_ALWAYS_NULL_EXCEPTION)
A
pointer which is null on an exception 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 exception path,
since the default case is often
infeasible.
空指针引用上调用去除引用方法,将发生空指针异常
61.
NP: Method does not check for null
argument
(NP_ARGUMENT_MIGHT_BE_NULL)
方法没有判断参数是否为空
62.
NP: close() invoked on a value that is
always null
(NP_CLOSING_NULL)
一个为空的对象调用
close
方法
63.
NP: Null value is guaranteed to be
dereferenced
(NP_GUARANTEED_DEREF)
There is a statement or branch that if
executed guarantees that a
value is
null at this point, and that value that is
guaranteed to be
dereferenced (except
on forward paths involving runtime
exceptions).
在正常的
null
判断分支上,对象去除引用操作是受保护的不允许的
64.
NP: Value is null and guaranteed to be
dereferenced on
exception path
(NP_GUARANTEED_DEREF_ON_EXCEPTION_PATH)
There is a statement or branch on an
exception path that if
executed
guarantees that a value is null at this point, and
that
value that is guaranteed to be
dereferenced (except on forward
paths
involving runtime exceptions).
65.
NP: Method call passes null to a
nonnull parameter
(NP_NONNULL_PARAM_VIOLATION)
方法中为
null
的参数没有被重新赋值
void test(){
}
String ss = null;
sya(ss);
public void sya(String ad){
}
es();
66.
NP: Method may return null, but is
declared @NonNull
(NP_NONNULL_RETURN_VIOLATION)
方法声明了返回值不能为空,但是方法中有可能返回
null
67.
NP: A known null value is checked to
see if it is an instance of a
type (NP_NULL_INSTANCEOF)
检查
一个为
null
的值是否是想要的类型对象,
< br>而不是由于粗心或者逻辑
错误引起的
68.
NP: Possible null pointer dereference
(NP_NULL_ON_SOME_PATH)
对象可能没有重新赋值
69.
NP: Possible null pointer dereference
in method on exception
path
(NP_NULL_ON_SOME_PATH_EXCEPTION)
A
reference 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.
在异常
null
值处理分支调用的方法上,<
/p>
可能存在对象
去除引用操作
70.
NP: Method call passes null for nonnull
parameter
(NP_NULL_PARAM_DEREF_ALL_TARG
ETS_DANGEROUS)
方法参数中声明为
nonnu
ll
类型的参数为
null
void
test(){
}
String ss =
null;
sya(ss);
public void sya(@nonnull String ad){
}
es();
71.
NP: Store of null value
into field annotated NonNull
(NP_STORE_INTO_NONNULL_FIELD)
为一个已经声明为不能为
null
值的属性赋值为
null
。
72.
Nm: Class defines equal(Object); should
it be equals(Object)?
(NM_BAD_EQUAL)
p>
类中定义了一个
equal
方法但是却不是
覆写的
Object
对象的
equal
s
方法
73.
Nm: Class defines hashcode(); should it
be hashCode()?
(NM_LCASE_HASHCODE)
类中定义了一个
hashCode
方法但是却不
是覆写的
Object
中的
hashC
ode
方法
74.
Nm: Class defines tostring(); should it
be toString()?
(NM_LCASE_TOSTRING)
类中定义了一个
toString
方法但是却不
是覆写的
Object
中的
toStr
ing
方法
75.
Nm: Apparent method/constructor
confusion
(NM_METHOD_CONSTRUCTOR_CONFUSION)
构造方法定义混乱,保证一个标准的构造函数。
SA(){
}
void SA(){
}
例如:
76.
Nm: Very confusing method names
(NM_VERY_CONFUSING)
混乱的方法命名,如
getName
和
getname
方
法同时出现的时候
77.
Nm: Method doesn't override
method in superclass due to
wrong
package for parameter (NM_WRONG_PACKAGE)
方法因为取了不同包中的同名的对象而没有正确覆写父类中的同名方
法
import
public class
A {
public int
f(Foo x) { return 17; }
}
----
import
public class B extends A {
public int f(Foo x) {
return 42; }
}
78.
QBA: Method assigns boolean literal in
boolean expression
(QBA_QUESTIONABLE_BOOLEAN_ASSIGNMENT) <
/p>
再
if
或者
wh
ile
表达式中使用
boolean
类
型的值时应该使用
==
去判断,
而不是采用
=
操作
79.
RC: Suspicious reference comparison
(RC_REF_COMPARISON)
比较两个对象值是否相等时应该采用
equals
方法,而不是
==
方法
80.
RE: Invalid syntax for
regular expression
(RE_BAD_SYNTAX_FOR_REGULAR_EXPRESSION)
对正则表达式使用了错误的语法,会抛出未经检查的异常,表明正则表
< br>达式模式中的语法错误。
81.
RE: tor used for regular expression
(RE_CANT_USE_FILE_SEPARATOR_AS_REGULAR_EXP
RESSION)
使用正则表达式使用了错误的文件分隔符,在
windows
系统中正则表
达式不会匹配’
’而应该使用
''
82.
RV: Random value from 0 to 1 is coerced
to the integer 0
(RV_01_TO_INT)
从
0
到
1
随机值被强制为整数值
0
。在强制得到一个整数之前,你可
能
想得到多个随机值。或使用
t
(
p>
n
)的方法。
83.
RV: Bad attempt to compute absolute
value of signed 32-bit
hashcode
(RV_ABSOLUTE_VALUE_OF_HASHCODE)
此代码生成一个
哈希码,然后计算该哈希码的绝对值。如果哈希码是
_VALUE
的,那么结果将是负数(因为
(
_V
ALUE
的)
==
_VALUE
的)。
在
2^ 32
值之外字符串有一个
p>
_VALUE
的
hashCode
包
括“polygenelubricants”,“GydZG_”和
“,”DESIGNING
WORKHOUSES “。
84.
RV: Bad attempt to compute absolute
value of signed 32-bit
random integer
(RV_ABSOLUTE_VALUE_OF_RANDOM_INT)
此代码生成
一个随机的符号整数,然后计算该随机整数的绝对值。如果
随机数生成数绝对值为
_VALUE
的,
那么结果将是负数
(因
为
(
_VALUE
的)
==
_VALUE
的)
。
85.
RV: Exception created and dropped
rather than thrown
(RV_EXCEPTION_NOT_THROWN)
此代
码创建一个异常
(或错误)
的对象,
但
不会用它做任何事情。
例如:
if (x < 0)
new
IllegalArgumentException(
这可能是程序员的意图抛出创建的异常:
if (x < 0)
throw new IllegalArgumentException(
nonnegative
86.
RV: Method ignores return value
(RV_RETURN_VALUE_IGNORED)
该方法的返回值应该进行检查
。
这种警告通常出现在调用一个不可变对
象的方法,认为它更新
了对象的值。例如:
String dateString =
getHeaderField(name);
();
p>
程序员似乎以为
trim
()方法将更新<
/p>
dateString
引用的字符串。但由
于字符串是不可改变的,
trim
()函数返回一个新字符串
值,在这里它
是被忽略了。该代码应更正:
String dateString =
getHeaderField(name);
dateString = ();
87.
RpC: Repeated conditional tests
(RpC_REPEATED_CONDITIONAL_TEST)
该代码包含对同一个条件试验了两次,
两边完全一样例如:
(如
X == 0
| | x ==
0
)。可能第二次出现是打算判断别的不同条件(如
X ==
0 | |
y== 0
)。
88.
SA: Double assignment of field
(SA_FIELD_DOUBLE_ASSIGNMENT)
方法中的字段包含了双重任务,例如:
int x;
public void
foo() {
x = x = 17;
}
这种为变量赋值是无用的,并可能表明一个逻辑错误或拼写
错误。
89.
SA: Self assignment of
field (SA_FIELD_SELF_ASSIGNMENT)
方法中包含自己对自己赋值的字段。例如:
int x;
public void foo() {
x =
x;
}
-
-
-
-
-
-
-
-
-
上一篇:Brocade(博科)交换机重要命令
下一篇:《28岁未成年》观后感精选5篇