|
This code compares a value that is guaranteed to be non-negative with a negative constant.
Repository: findbugs
Key: INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE
Available since 07 Jan 2014
|
|
Signed bytes can only have a value in the range -128 to 127. Comparing
a signed byte with a value outside that range is vacuous and likely to be incorrect.
To convert a signed byte b to an unsigned value in the range 0..255,
use 0xff & b
Repository: findbugs
Key: INT_BAD_COMPARISON_WITH_SIGNED_BYTE
Available since 07 Jan 2014
|
|
This code passes a constant month
value outside the expected range of 0..11 to a method.
Repository: findbugs
Key: DMI_BAD_MONTH
Available since 07 Jan 2014
|
|
Adds a byte value and a value which is known to the 8 lower bits clear.
Values loaded from a byte array are sign extended to 32 bits
before any any bitwise operations are performed on the value.
Thus, if b[0] contains the value 0xff , and
x is initially 0, then the code
((x << 8) + b[0]) will sign extend 0xff
to get 0xffffffff , and thus give the value
0xffffffff as the result.
In particular, the following code for packing a byte array into an int is badly wrong:
int result = 0;
for(int i = 0; i < 4; i++)
result = ((result << 8) + b[i]);
The following idiom will work instead:
int result = 0;
for(int i = 0; i < 4; i++)
result = ((result << 8) + (b[i] & 0xff));
Repository: findbugs
Key: BIT_ADD_OF_SIGNED_BYTE
Available since 07 Jan 2014
|
|
Loads a value from a byte array and performs a bitwise OR with
that value. Values loaded from a byte array are sign extended to 32 bits
before any any bitwise operations are performed on the value.
Thus, if b[0] contains the value 0xff , and
x is initially 0, then the code
((x << 8) | b[0]) will sign extend 0xff
to get 0xffffffff , and thus give the value
0xffffffff as the result.
In particular, the following code for packing a byte array into an int is badly wrong:
int result = 0;
for(int i = 0; i < 4; i++)
result = ((result << 8) | b[i]);
The following idiom will work instead:
int result = 0;
for(int i = 0; i < 4; i++)
result = ((result << 8) | (b[i] & 0xff));
Repository: findbugs
Key: BIT_IOR_OF_SIGNED_BYTE
Available since 07 Jan 2014
|
|
This method calls equals(Object) on two references of unrelated
interface types, where neither is a subtype of the other,
and there are no known non-abstract classes which implement both interfaces.
Therefore, the objects being compared
are unlikely to be members of the same class at runtime
(unless some application classes were not analyzed, or dynamic class
loading can occur at runtime).
According to the contract of equals(),
objects of different
classes should always compare as unequal; therefore, according to the
contract defined by java.lang.Object.equals(Object),
the result of this comparison will always be false at runtime.
Repository: findbugs
Key: EC_UNRELATED_INTERFACES
Available since 07 Jan 2014
|
|
This method calls equals(Object) on two references of different
class types with no common subclasses.
Therefore, the objects being compared
are unlikely to be members of the same class at runtime
(unless some application classes were not analyzed, or dynamic class
loading can occur at runtime).
According to the contract of equals(),
objects of different
classes should always compare as unequal; therefore, according to the
contract defined by java.lang.Object.equals(Object),
the result of this comparison will always be false at runtime.
Repository: findbugs
Key: EC_UNRELATED_TYPES
Available since 07 Jan 2014
|
|
This method calls equals(Object) on two references, one of which is a class
and the other an interface, where neither the class nor any of its
non-abstract subclasses implement the interface.
Therefore, the objects being compared
are unlikely to be members of the same class at runtime
(unless some application classes were not analyzed, or dynamic class
loading can occur at runtime).
According to the contract of equals(),
objects of different
classes should always compare as unequal; therefore, according to the
contract defined by java.lang.Object.equals(Object),
the result of this comparison will always be false at runtime.
Repository: findbugs
Key: EC_UNRELATED_CLASS_AND_INTERFACE
Available since 07 Jan 2014
|
|
This 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 .
Repository: findbugs
Key: EC_NULL_ARG
Available since 07 Jan 2014
|
|
Unless an annotation has itself been annotated with @Retention(RetentionPolicy.RUNTIME), the annotation can't be observed using reflection
(e.g., by using the isAnnotationPresent method).
.
Repository: findbugs
Key: DMI_ANNOTATION_IS_NOT_VISIBLE_TO_REFLECTION
Available since 07 Jan 2014
|
|
This method compares an expression such as
((event.detail & SWT.SELECTED) > 0) .
Using bit arithmetic and then comparing with the greater than operator can
lead to unexpected results (of course depending on the value of
SWT.SELECTED). If SWT.SELECTED is a negative number, this is a candidate
for a bug. Even when SWT.SELECTED is not negative, it seems good practice
to use '!= 0' instead of '> 0'.
Boris Bokowski
Repository: findbugs
Key: BIT_SIGNED_CHECK_HIGH_BIT
Available since 07 Jan 2014
|
|
This method compares an expression of the form (e & 0) to 0,
which will always compare equal.
This may indicate a logic error or typo.
Repository: findbugs
Key: BIT_AND_ZZ
Available since 07 Jan 2014
|
|
This 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.
Repository: findbugs
Key: MF_CLASS_MASKS_FIELD
Available since 07 Jan 2014
|
|
This method overrides a method found in a parent class, where that class is an Adapter that implements
a listener defined in the java.awt.event or javax.swing.event package. As a result, this method will not
get called when the event occurs.
Repository: findbugs
Key: BOA_BADLY_OVERRIDDEN_ADAPTER
Available since 07 Jan 2014
|
|
close() is being invoked on a value that is always null. If this statement is executed, a null pointer exception will occur. But the big risk here you never close something that should be closed.
Repository: findbugs
Key: NP_CLOSING_NULL
Available since 07 Jan 2014
|
|
This call to a generic collection's method would only make sense if a collection contained
itself (e.g., if s.contains(s) were true). This is unlikely to be true and would cause
problems if it were true (such as the computation of the hash code resulting in infinite recursion).
It is likely that the wrong value is being passed as a parameter.
Repository: findbugs
Key: DMI_COLLECTIONS_SHOULD_NOT_CONTAIN_THEMSELVES
Available since 07 Jan 2014
|
|
(Javadoc)
A ScheduledThreadPoolExecutor with zero core threads will never execute anything; changes to the max pool size are ignored.
Repository: findbugs
Key: DMI_SCHEDULED_THREAD_POOL_EXECUTOR_WITH_ZERO_CORE_THREADS
Available since 07 Jan 2014
|
|
This instruction assigns a class literal to a variable and then never uses it.
The behavior of this differs in Java 1.4 and in Java 5.
In Java 1.4 and earlier, a reference to Foo.class would force the static initializer
for Foo to be executed, if it has not been executed already.
In Java 5 and later, it does not.
See Sun's article on Java SE compatibility
for more details and examples, and suggestions on how to force class initialization in Java 5.
Repository: findbugs
Key: DLS_DEAD_STORE_OF_CLASS_LITERAL
Available since 07 Jan 2014
|
|
This class is an inner class, but should probably be a static inner class. As it is, there is a serious danger of a deadly embrace between the inner class and the thread local in the outer class. Because the inner class isn't static, it retains a reference to the outer class. If the thread local contains a reference to an instance of the inner class, the inner and outer instance will both be reachable and not eligible for garbage collection.
Repository: findbugs
Key: SIC_THREADLOCAL_DEADLY_EMBRACE
Available since 07 Jan 2014
|
|
If you want to remove all elements from a collection c , use c.clear ,
not c.removeAll(c) .
Repository: findbugs
Key: DMI_USING_REMOVEALL_TO_CLEAR_COLLECTION
Available since 07 Jan 2014
|
|
This code opens a file in append mode and then wraps the result in an object output stream.
This won't allow you to append to an existing object output stream stored in a file. If you want to be
able to append to an object output stream, you need to keep the object output stream open.
The only situation in which opening a file in append mode and the writing an object output stream
could work is if on reading the file you plan to open it in random access mode and seek to the byte offset
where the append started.
TODO: example.
Repository: findbugs
Key: IO_APPENDING_TO_OBJECT_OUTPUT_STREAM
Available since 07 Jan 2014
|
|
This code checks to see if a floating point value is equal to the special
Not A Number value (e.g., if (x == Double.NaN) ). However,
because of the special semantics of NaN , no value
is equal to Nan , including NaN . Thus,
x == Double.NaN always evaluates to false.
To check to see if a value contained in x
is the special Not A Number value, use
Double.isNaN(x) (or Float.isNaN(x) if
x is floating point precision).
Repository: findbugs
Key: FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER
Available since 07 Jan 2014
|
|
This method contains a double assignment of a field; e.g.
int x,y;
public void foo() {
x = x = 17;
}
Assigning to a field twice is useless, and may indicate a logic error or typo.
Repository: findbugs
Key: SA_FIELD_DOUBLE_ASSIGNMENT
Available since 07 Jan 2014
|
|
The Double.longBitsToDouble method is invoked, but a 32 bit int value is passed
as an argument. This almostly certainly is not intended and is unlikely
to give the intended result.
Repository: findbugs
Key: DMI_LONG_BITS_TO_DOUBLE_INVOKED_ON_INT
Available since 07 Jan 2014
|
|
This class defines an equals method that always returns false. This means that an object is not equal to itself, and it is impossible to create useful Maps or Sets of this class. More fundamentally, it means
that equals is not reflexive, one of the requirements of the equals method.
The likely intended semantics are object identity: that an object is equal to itself. This is the behavior inherited from class Object . If you need to override an equals inherited from a different
superclass, you can use use:
public boolean equals(Object o) { return this == o; }
Repository: findbugs
Key: EQ_ALWAYS_FALSE
Available since 07 Jan 2014
|