From e46c3b1ca566b15d4df793026e55893a73c417d2 Mon Sep 17 00:00:00 2001
From: simonbrandhof The correct way to do get an array of a specific type from a collection is to use There is one common/known exception exception to this. The toArray() method of lists returned by Arrays.asList(...) will return a covariantly typed array. For example, When a B is constructed, the constructor for the A class is invoked before the constructor for B sets value. Thus, when the constructor for A invokes getValue, an uninitialized value is read for value.c.toArray(new String[]);
or c.toArray(new String[c.size()]);
(the latter is slightly more efficient).Arrays.asArray(new String[] { "a" }).toArray()
will return a String []. FindBugs attempts to detect and suppress such cases, but may miss some.
x == 0 || y == 0
).
]]>
putNextEntry()
and
closeEntry()
.]]>
putNextEntry()
and
closeEntry()
.]]>
If all clone() methods call super.clone(), then they are guaranteed to use Object.clone(), which always returns an object of the correct type.
]]>java.net.URI
instead.
(e.g., by using the isAnnotationPresent method).
.]]>
java.net.URI
instead.
hard or impossible for your code to be invoked by other code.
Consider throwing a RuntimeException instead.]]>
java.net.URI
instead.
or Runtime.runFinalizersOnExit for any reason: they are among the most
dangerous methods in the Java libraries. -- Joshua Bloch]]>
String
directly.]]>
String.toString()
is just a redundant operation.
Just use the String.]]>Boolean
objects instead.]]>
Integer
, Short
, Character
, and Byte
.
]]>
Double
and Float
.
]]>
versions instead.
]]>e2
is of type Float
, then e1
is unbox
converted to a floating point value, and boxed. See JLS Section 15.25.
]]>
new Double(d).intValue()
). Just perform direct primitive coercion (e.g., (int) d
).]]>Condition
interface.
]]>
Random.nextInt(n)
method.
]]>
r.nextInt(n)
, rather than using (int)(r.nextDouble() * n)
.
]]>
finalize()
method should have protected access,
not public.]]>finalize()
methods are useless, so they should
be deleted.]]>finalize()
method, making it
redundant. Delete it.]]>
super.finalize()
.]]>
boolean equals(Object)
method.
]]>
boolean equals(Object)
method.
]]>
java.lang.Object
, the parameter of equals()
must have type java.lang.Object
.]]>
Foo.class == o.getClass()
).
It is better to check if this.getClass() == o.getClass()
.
]]>
this
object. There might not be
this code, but it is worth reviewing.
]]>
hashCode
implementation to use is:
return 42; // any arbitrary constant will do
}]]>
equals()
method. Therefore, the class may
violate the invariant that equal objects must have equal hashcodes.]]>
hashCode
implementation to use is:
return 42; // any arbitrary constant will do
}]]>
hashCode
implementation to use is:
define the hashCode()
method
to throw UnsupportedOperationException
.]]>
hashCode
implementation to use is:
override hashCode()
. Therefore, the class may violate the
invariant that equal objects must have equal hashcodes.]]>
hashCode
implementation to use is:
java.lang.Object
, the parameter of equals()
must have type java.lang.Object
.]]>
String.intern()
method, the same string
value may be represented by two different String objects. Consider
using the equals(Object)
method instead.]]>
equals(Object)
method instead.]]>
equals(Object)
method instead.]]>
Comparable
interface, the parameter of compareTo()
must have type java.lang.Object
.]]>
Thread.start()
is the right method to call.]]>
NoSuchElementException
if is called when there are no more elements to return.]]>
Since there normally exist only two Boolean objects, this code could be synchronizing on the same object as other, unrelated code, leading to unresponsiveness and possible deadlock
]]>Foo
's from different packages.
]]>
writeObject()
method which is synchronized;
however, no other method of the class is synchronized.]]>NullPointerException
when the code is executed.]]>Also note that FindBugs considers the default case of a switch statement to be an exception path, since the default case is often infeasible.
]]>Also note that FindBugs considers the default case of a switch statement to be an exception path, since the default case is often infeasible.
]]>NullPointerException
when the code is executed.
]]>
NullPointerException
when the code is
dereferenced.
]]>
NullPointerException
when the code is
dereferenced.
]]>
NullPointerException
when the code is
dereferenced.
]]>
NullPointerException
when the code is
always dereferenced.
]]>
NullPointerException
when the code is
which it overrides) is declared to return @NonNull.
]]>
NullPointerException
when the code is
instead.
]]>
NullPointerException
when the code is
other code to break. Return the empty string or some other appropriate string rather than null.
]]>
NullPointerException
when the code is
(except on forward paths involving runtime exceptions).
]]>
NullPointerException
when the code is
(except on forward paths involving runtime exceptions).
]]>
finally
block to ensure that streams are
closed.]]>
finally
block to ensure that streams are
closed.]]>
File.listFiles()
returns an empty list
if given a directory containing no files, and returns null if the file
is not a directory.]]>
if
statement:
}
]]>
if
statement, e.g.:
System.out.println("Hello, " + argv[0]);
]]>
false
.]]>
false
.]]>
on the object. Calling wait() without a lock held will result in
an IllegalMonitorStateException
being thrown.]]>
IllegalMonitorStateException
being thrown.]]>
on the object. Calling notify() or notifyAll() without a lock held will result in
an IllegalMonitorStateException
being thrown.]]>
IllegalMonitorStateException
being thrown.]]>
Such assignments are useless, and may indicate a logic error or typo.
]]>
Such assignments are useless, and may indicate a logic error or typo.
]]>Assigning to a field twice is useless, and may indicate a logic error or typo.
]]>Assigning the same value to a variable twice is useless, and may indicate a logic error or typo.
]]>Integer.MIN_VALUE
, then the result will be negative as
Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE
).
]]>
Integer.MIN_VALUE
, then the result will be negative as well (sin
Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE
).
]]>
Math.abs(x.hashCode()%n)
]]>
b
to an unsigned value in the range 0..255
use 0xff & b
]]>
0xff & b
]]>
0xff & b
the same value (e.g., x <= Integer.MAX_VALUE).
]]>
lock()
and unlock()
methods instead.
]]>
public static junit.framework.TestSuite suite()]]>