| Active/Severity | Name [expand/collapse] | Plugin | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Avoid Array Loops
Instead of copying data between two arrays, use System.arrayCopy method
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Assert As Identifier
Finds all places 'assert' is used as an identifier is used.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Calling Finalize
Object.finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Catching NPE
Code should never throw NPE under normal circumstances. A catch block may hide the original error, causing other more subtle errors in its wake.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Catching Throwable
This is dangerous because it casts too wide a net; it can catch things like OutOfMemoryError.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Decimal Literals In Big Decimal Constructor
One might assume that new BigDecimal(.1) is exactly equal to .1, but it is actually equal to .1000000000000000055511151231257827021181583404541015625. This is so because .1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the long value that is being passed in to the constructor is not exactly equal to .1, appearances notwithstanding. The (String) constructor, on the other hand, is perfectly predictable: 'new BigDecimal(.1)' is exactly equal to .1, as one would expect. Therefore, it is generally recommended that the (String) constructor be used in preference to this one.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Duplicate Literals
Code containing duplicate String literals can usually be improved by declaring the String as a constant field. Example :
public class Foo {
private void bar() {
buz("Howdy");
buz("Howdy");
buz("Howdy");
buz("Howdy");
}
private void buz(String x) {}
}
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Enum As Identifier
Finds all places 'enum' is used as an identifier is used.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Instanceof Checks In Catch Clause
Each caught exception type should be handled in its own catch clause.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Print Stack Trace
Avoid printStackTrace(); use a logger call instead.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Rethrowing Exception
Catch blocks that merely rethrow a caught exception only add to code size and runtime complexity.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Throwing Null Pointer Exception
Avoid throwing a NullPointerException - it's confusing because most people will assume that the virtual machine threw it. Consider using an IllegalArgumentException instead; this will be clearly seen as a programmer-initiated exception.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Avoid Throwing Raw Exception Types
Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable, Exception, or Error, use a subclassed exception or error instead.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Abstract class defines covariant compareTo() method
This class defines a covariant version of
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Abstract class defines covariant equals() method
This class defines a covariant version of
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Certain swing methods needs to be invoked in Swing thread
(From JDC Tech Tip): The Swing methods show(), setVisible(), and pack() will create the associated peer for the frame. With the creation of the peer, the system creates the event dispatch thread. This makes things problematic because the event dispatch thread could be notifying listeners while pack and validate are still processing. This situation could result in two threads going through the Swing component-based GUI -- it's a serious flaw that could result in deadlocks or other related threading issues. A pack call causes components to be realized. As they are being realized (that is, not necessarily visible), they could trigger listener notification on the event dispatch thread.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Check for sign of bitwise operation
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
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class defines clone() but doesn't implement Cloneable
This class defines a clone() method but the class doesn't implement Cloneable. There are some situations in which this is OK (e.g., you want to control how subclasses can clone themselves), but just make sure that this is what you intended.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class defines compareTo(...) and uses Object.equals()
This class defines a From the JavaDoc for the compareTo method in the Comparable interface:
It is strongly recommended, but not strictly required that
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class defines equals() and uses Object.hashCode()
This class overrides If you don't think instances of this class will ever be inserted into a HashMap/HashTable,
the recommended public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class defines equals() but not hashCode()
This class overrides
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class defines hashCode() and uses Object.equals()
This class defines a If you don't think instances of this class will ever be inserted into a HashMap/HashTable,
the recommended public int hashCode() {
assert false : "hashCode not designed";
return 42; // any arbitrary constant will do
}
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class defines hashCode() but not equals()
This class defines a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class implements Cloneable but does not define or use clone method
Class implements Cloneable but does not define or use the clone method.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class inherits equals() and uses Object.hashCode()
This class inherits If you don't want to define a hashCode method, and/or don't
believe the object will ever be put into a HashMap/Hashtable,
define the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class is Externalizable but doesn't define a void constructor
This class implements the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class is not derived from an Exception, even though it is named as such
This class is not derived from another exception, but ends with 'Exception'. This will be confusing to users of this class.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class is Serializable but its superclass doesn't define a void constructor
This class implements the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class names shouldn't shadow simple name of implemented interface
This class/interface has a simple name that is identical to that of an implemented/extended interface, except
that the interface is in a different package (e.g.,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Class names shouldn't shadow simple name of superclass
This class has a simple name that is identical to that of its superclass, except
that its superclass is in a different package (e.g.,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Classloaders should only be created inside doPrivileged block
This code creates a classloader, which requires a security manager. If this code will be granted security permissions, but might be invoked by code that does not have security permissions, then the classloader creation needs to occur inside a doPrivileged block.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - clone method does not call super.clone()
This non-final class defines a clone() method that does not call super.clone(). If this class ("A") is extended by a subclass ("B"), and the subclass B calls super.clone(), then it is likely that B's 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.clone(), which always returns an object of the correct type.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Clone method may return null
This clone method seems to return null in some circumstances, but clone is never allowed to return a null value. If you are convinced this path is unreachable, throw an AssertionError instead.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Comparator doesn't implement Serializable
This class implements the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Comparison of String objects using == or !=
This code compares
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Comparison of String parameter using == or !=
This code compares a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Confusing method names
The referenced methods have names that differ only by capitalization.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Covariant compareTo() method defined
This class defines a covariant version of
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Covariant equals() method defined
This class defines a covariant version of
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Creates an empty jar file entry
The code calls
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Creates an empty zip file entry
The code calls
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Dubious catching of IllegalMonitorStateException
IllegalMonitorStateException is generally only thrown in case of a design flaw in your code (calling wait or notify on an object you do not hold a lock on).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Empty finalizer should be deleted
Empty
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Equals checks for noncompatible operand
This equals method is checking to see if the argument is some incompatible type (i.e., a class that is neither a supertype nor subtype of the class that defines the equals method). For example, the Foo class might have an equals method that looks like:
This is considered bad practice, as it makes it very hard to implement an equals method that is symmetric and transitive. Without those properties, very unexpected behavoirs are possible.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - equals method fails for subtypes
This class has an equals method that will be broken if it is inherited by subclasses.
It compares a class literal with the class of the argument (e.g., in class
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Equals method should not assume anything about the type of its argument
The
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - equals() method does not check for null argument
This implementation of equals(Object) violates the contract defined by java.lang.Object.equals() because it does not check for null being passed as the argument. All equals() methods should return false if passed a null value.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Explicit invocation of finalizer
This method contains an explicit invocation of the If a connected set of objects beings finalizable, then the VM will invoke the finalize method on all the finalizable object, possibly at the same time in different threads. Thus, it is a particularly bad idea, in the finalize method for a class X, invoke finalize on objects referenced by X, because they may already be getting finalized in a separate thread.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Fields of immutable classes should be final
The class is annotated with net.jcip.annotations.Immutable, and the rules for that annotation require that all fields are final. .
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Finalizer does not call superclass finalizer
This
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Finalizer does nothing but call superclass finalizer
The only thing this
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Finalizer nullifies superclass finalizer
This empty
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Finalizer nulls fields
This finalizer nulls out fields. This is usually an error, as it does not aid garbage collection, and the object is going to be garbage collected anyway.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Finalizer only nulls fields
This finalizer does nothing except null out fields. This is completely pointless, and requires that the object be garbage collected, finalized, and then garbage collected again. You should just remove the finalize method.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Iterator next() method can't throw NoSuchElementException
This class implements the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method doesn't override method in superclass due to wrong package for parameter
The method in the subclass doesn't override a similar method in a superclass because the type of a parameter doesn't exactly match the type of the corresponding parameter in the superclass. For example, if you have:
The In this case, the subclass does define a method with a signature identical to the method in the superclass, so this is presumably understood. However, such methods are exceptionally confusing. You should strongly consider removing or deprecating the method with the similar but not identical signature.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method ignores exceptional return value
This method returns a value that is not checked. The return value should be checked
since it can indicate an unusual or unexpected function execution. For
example, the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method ignores results of InputStream.read()
This method ignores the return value of one of the variants of
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method ignores results of InputStream.skip()
This method ignores the return value of
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method invoked that should be only be invoked inside a doPrivileged block
This code invokes a method that requires a security permission check. If this code will be granted security permissions, but might be invoked by code that does not have security permissions, then the invocation needs to occur inside a doPrivileged block.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method invokes dangerous method runFinalizersOnExit
Never call System.runFinalizersOnExit or Runtime.runFinalizersOnExit for any reason: they are among the most dangerous methods in the Java libraries. -- Joshua Bloch
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - 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 instead.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method may fail to close database resource
The method creates a database resource (such as a database connection or row set), does not assign it to any fields, pass it to other methods, or return it, and does not appear to close the object on all paths out of the method. Failure to close database resources on all paths out of a method may result in poor performance, and could cause the application to have problems communicating with the database.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method may fail to close database resource on exception
The method creates a database resource (such as a database connection or row set), does not assign it to any fields, pass it to other methods, or return it, and does not appear to close the object on all exception paths out of the method. Failure to close database resources on all paths out of a method may result in poor performance, and could cause the application to have problems communicating with the database.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method may fail to close stream
The method creates an IO stream object, does not assign it to any
fields, pass it to other methods that might close it,
or return it, and does not appear to close
the stream on all paths out of the method. This may result in
a file descriptor leak. It is generally a good
idea to use a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method may fail to close stream on exception
The method creates an IO stream object, does not assign it to any
fields, pass it to other methods, or return it, and does not appear to close
it on all possible exception paths out of the method.
This may result in a file descriptor leak. It is generally a good
idea to use a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method might drop exception
This 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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method might ignore exception
This method might ignore an exception. In general, exceptions should be handled or reported in some way, or they should be thrown out of the method.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Method with Boolean return type returns explicit null
A method that returns either Boolean.TRUE, Boolean.FALSE or null is an accident waiting to happen. This method can be invoked as though it returned a value of type boolean, and the compiler will insert automatic unboxing of the Boolean value. If a null value is returned, this will result in a NullPointerException.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Needless instantiation of class that only supplies static methods
This class allocates an object that is based on a class that only supplies static methods. This object does not need to be created, just access the static methods directly using the class name as a qualifier.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Non-serializable class has a serializable inner class
This Serializable class is an inner class of a non-serializable class. Thus, attempts to serialize it will also attempt to associate instance of the outer class with which it is associated, leading to a runtime error. If possible, making the inner class a static inner class should solve the problem. Making the outer class serializable might also work, but that would mean serializing an instance of the inner class would always also serialize the instance of the outer class, which it often not what you really want.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Non-serializable value stored into instance field of a serializable class
A non-serializable value is stored into a non-transient field of a serializable class.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Random object created and used only once
This code creates a java.util.Random object, uses it to generate one random number, and then discards the Random object. This produces mediocre quality random numbers and is inefficient. If possible, rewrite the code so that the Random object is created once and saved, and each time a new random number is required invoke a method on the existing Random object to obtain it. If it is important that the generated Random numbers not be guessable, you must not create a new Random for each random number; the values are too easily guessable. You should strongly consider using a java.security.SecureRandom instead (and avoid allocating a new SecureRandom for each random number needed).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - serialVersionUID isn't final
This class defines a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - serialVersionUID isn't long
This class defines a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - serialVersionUID isn't static
This class defines a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Static initializer creates instance before all static final fields assigned
The class's static initializer creates an instance of the class before all of the static final fields are assigned.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Store of non serializable object into HttpSession
This code seems to be storing a non-serializable object into an HttpSession. If this session is passivated or migrated, an error will result.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Superclass uses subclass during initialization
During the initialization of a class, the class makes an active use of a subclass.
That subclass will not yet be initialized at the time of this use.
For example, in the following code,
public class CircularClassInitialization {
static class InnerClassSingleton extends CircularClassInitialization {
static InnerClassSingleton singleton = new InnerClassSingleton();
}
static CircularClassInitialization foo = InnerClassSingleton.singleton;
}
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Suspicious reference comparison
This method compares two reference values using the == or != operator, where the correct way to compare instances of this type is generally with the equals() method. Examples of classes which should generally not be compared by reference are java.lang.Integer, java.lang.Float, etc.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - The readResolve method must be declared with a return type of Object.
In order for the readResolve method to be recognized by the serialization mechanism, it must be declared to have a return type of Object.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - toString method may return null
This toString method seems to return null in some circumstances. A liberal reading of the spec could be interpreted as allowing this, but it is probably a bad idea and could cause other code to break. Return the empty string or some other appropriate string rather than null.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Transient field that isn't set by deserialization.
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Usage of GetResource may be unsafe if class is extended
Calling
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Use of identifier that is a keyword in later versions of Java
This identifier is used as a keyword in later versions of Java. This code, and any code that references this API, will need to be changed in order to compile it in later versions of Java.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Use of identifier that is a keyword in later versions of Java
The identifier is a word that is reserved as a keyword in later versions of Java, and your code will need to be changed in order to compile it in later versions of Java.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Bad practice - Very confusing method names (but perhaps intentional)
The referenced methods have names that differ only by capitalization. This is very confusing because if the capitalization were identical then one of the methods would override the other. From the existence of other methods, it seems that the existence of both of these methods is intentional, but is sure is confusing. You should try hard to eliminate one of them, unless you are forced to have both due to frozen APIs.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Big Integer Instantiation
Don't create instances of already existing BigInteger (BigInteger.ZERO, BigInteger.ONE) and for 1.5 on, BigInteger.TEN and BigDecimal (BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN)
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Boolean Instantiation
Avoid instantiating Boolean objects; you can reference Boolean.TRUE, Boolean.FALSE, or call Boolean.valueOf() instead.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Broken Null Check
The null check is broken since it will throw a Nullpointer itself. The reason is that a method is called on the object when it is null. It is likely that you used || instead of && or vice versa.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Class Cast Exception With To Array
if you need to get an array of a class from your Collection, you should pass an array of the desidered class as the parameter of the toArray method. Otherwise you will get a ClassCastException.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Clone Throws Clone Not Supported Exception
The method clone() should throw a CloneNotSupportedException.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Close Resource
Ensure that resources (like Connection, Statement, and ResultSet objects) are always closed after use. It does this by looking for code patterned like :
Connection c = openConnection();
try {
// do stuff, and maybe catch something
} finally {
c.close();
}
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collapsible If Statements
Sometimes two 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Compare Objects With Equals
Use equals() to compare object references; avoid comparing them with ==.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constant Name
Checks that constant names conform to the specified format
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constructor Calls Overridable Method
Calling overridable methods during construction poses a risk of invoking methods on an incompletely constructed object
and can be difficult to discern. It may leave the sub-class unable to construct its superclass or forced to replicate
the construction process completely within itself, losing the ability to call super().
If the default constructor contains a call to an overridable method, the subclass may be completely uninstantiable.
Note that this includes method calls throughout the control flow graph - i.e., if a constructor Foo() calls
a private method bar() that calls a public method buz(), this denotes a problem.
Example :
public class SeniorClass {
public SeniorClass(){
toString(); //may throw NullPointerException if overridden
}
public String toString(){
return "IAmSeniorClass";
}
}
public class JuniorClass extends SeniorClass {
private String name;
public JuniorClass(){
super(); //Automatic call leads to NullPointerException
name = "JuniorClass";
}
public String toString(){
return name.toUpperCase();
}
}
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - "." used for regular expression
A String function is being invoked and "." is being passed to a parameter that takes a regular expression as an argument. Is this what you intended? For example s.replaceAll(".", "/") will return a String in which every character has been replaced by a / character.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - A collection is added to itself
A collection is added to itself. As a result, computing the hashCode of this set will throw a StackOverflowException.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - A known null value is checked to see if it is an instance of a type
This instanceof test will always return false, since the value being checked is guaranteed to be null. Although this is safe, make sure it isn't an indication of some misunderstanding or some other logic error.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - A parameter is dead upon entry to a method 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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - An apparent infinite loop
This loop doesn't seem to have a way to terminate (other than by perhaps throwing an exception).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - An apparent infinite recursive loop
This method unconditionally invokes itself. This would seem to indicate an infinite recursive loop that will result in a stack overflow.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Apparent method/constructor confusion
This regular method has the same name as the class it is defined in. It is likely that this was intended to be a constructor. If it was intended to be a constructor, remove the declaration of a void return value. If you had accidently defined this method, realized the mistake, defined a proper constructor but can't get rid of this method due to backwards compatibility, deprecate the method.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Array formatted in useless way using format string
One of the arguments being formatted with a format string is an array. This will be formatted
using a fairly useless format, such as [I@304282, which doesn't actually show the contents
of the array.
Consider wrapping the array using
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Bad attempt to compute absolute value of signed 32-bit hashcode
This code generates a hashcode and then computes
the absolute value of that hashcode. If the hashcode
is
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Bad attempt to compute absolute value of signed 32-bit random integer
This code generates a random signed integer and then computes
the absolute value of that random integer. If the number returned by the random number
generator is
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Bad comparison of nonnegative value with negative constant
This code compares a value that is guaranteed to be non-negative with a negative constant.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Bad comparison of signed byte
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
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Bad constant value for month
This code passes a constant month value outside the expected range of 0..11 to a method.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Bitwise add of signed byte value
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 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));
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Bitwise OR of signed byte value
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 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));
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Call to equals() comparing different interface types
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Call to equals() comparing different types
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Call to equals() comparing unrelated class and interface
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Call to equals() with null argument
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
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Can't use reflection to check for presence of annotation without runtime retention
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). .
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Check for sign of bitwise operation
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
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Check to see if ((...) & 0) == 0
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Class defines field that masks a superclass field
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Class overrides a method implemented in super class Adapter wrongly
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - close() invoked on a value that is always null
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Collections should not contain themselves
This call to a generic collection's method would only make sense if a collection contained
itself (e.g., if
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Covariant equals() method defined 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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Covariant equals() method defined, Object.equals(Object) inherited
This class defines a covariant version of the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Creation of ScheduledThreadPoolExecutor with zero core threads
(Javadoc) A ScheduledThreadPoolExecutor with zero core threads will never execute anything; changes to the max pool size are ignored.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Dead store of class literal
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 See Sun's article on Java SE compatibility for more details and examples, and suggestions on how to force class initialization in Java 5.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Deadly embrace of non-static inner class and thread local
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Don't use removeAll to clear a collection
If you want to remove all elements from a collection
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Doomed attempt to append to an object output stream
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Doomed test for equality to NaN
This code checks to see if a floating point value is equal to the special
Not A Number value (e.g.,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Double assignment of field
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Double.longBitsToDouble invoked on an int
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - equals method always returns false
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
public boolean equals(Object o) { return this == o; }
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - equals method always returns true
This class defines an equals method that always returns true. This is imaginative, but not very smart. Plus, it means that the equals method is not symmetric.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - equals method compares class names rather than class objects
This method checks to see if two objects are the same class by checking to see if the names of their classes are equal. You can have different classes with the same name if they are loaded by different class loaders. Just check to see if the class objects are the same.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - equals method overrides equals in superclass and may not be symmetric
This class defines an equals method that overrides an equals method in a superclass. Both equals methods
methods use
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - equals() method defined that doesn't override equals(Object)
This class defines an
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - equals() method defined that doesn't override Object.equals(Object)
This class defines an
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - equals() used to compare array and nonarray
This method invokes the .equals(Object o) to compare an array and a reference that doesn't seem to be an array. If things being compared are of different types, they are guaranteed to be unequal and the comparison is almost certainly an error. Even if they are both arrays, the equals method on arrays only determines of the two arrays are the same object. To compare the contents of the arrays, use java.util.Arrays.equals(Object[], Object[]).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - equals(...) used to compare incompatible arrays
This method invokes the .equals(Object o) to compare two arrays, but the arrays of of incompatible types (e.g., String[] and StringBuffer[], or String[] and int[]). They will never be equal. In addition, when equals(...) is used to compare arrays it only checks to see if they are the same array, and ignores the contents of the arrays.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Exception created and dropped rather than thrown
This code creates an exception (or error) object, but doesn't do anything with it. For example, something like
It was probably the intent of the programmer to throw the created exception:
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Explicit annotation inconsistent with use
A value is used in a way that requires it to be never be a value denoted by a type qualifier, but there is an explicit annotation stating that it is not known where the value is prohibited from having that type qualifier. Either the usage or the annotation is incorrect.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Explicit annotation inconsistent with use
A value is used in a way that requires it to be always be a value denoted by a type qualifier, but there is an explicit annotation stating that it is not known where the value is required to have that type qualifier. Either the usage or the annotation is incorrect.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Field only ever set to null
All writes to this field are of the constant value null, and thus all reads of the field will return null. Check for errors, or remove it if it is useless.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - File.separator used for regular expression
The code here uses
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Format string placeholder incompatible with passed argument
The format string placeholder is incompatible with the corresponding
argument. For example,
The %d placeholder requires a numeric argument, but a string value is passed instead. A runtime exception will occur when this statement is executed.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Format string references missing argument
Not enough arguments are passed to satisfy a placeholder in the format string. A runtime exception will occur when this statement is executed.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Futile attempt to change max pool size of ScheduledThreadPoolExecutor
(Javadoc) 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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - hasNext method invokes next
The hasNext() method invokes the next() method. This is almost certainly wrong, since the hasNext() method is not supposed to change the state of the iterator, and the next method is supposed to change the state of the iterator.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Illegal format string
The format string is syntactically invalid, and a runtime exception will occur when this statement is executed.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Impossible cast
This cast will always throw a ClassCastException.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Impossible downcast
This cast will always throw a ClassCastException. The analysis believes it knows the precise type of the value being cast, and the attempt to downcast it to a subtype will always fail by throwing a ClassCastException.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Impossible downcast of toArray() result
This code is casting the result of calling toArray() on a collection to a type more specific than Object[], as in: String[] getAsArray(Collection This will usually fail by throwing a ClassCastException. The 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,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Incompatible bit masks
This method compares an expression of the form (e & 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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Incompatible bit masks
This method compares an expression of the form (e | 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 perform a membership test in a bit set, but uses the bitwise OR operator ("|") instead of bitwise AND ("&").
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - instanceof will always return false
This instanceof test will always return false. Although this is safe, make sure it isn't an indication of some misunderstanding or some other logic error.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - int value cast to double and then passed to Math.ceil
This code converts an int value to a double precision floating point number and then passing the result to the Math.ceil() function, which rounds a double to the next higher integer value. This operation should always be a no-op, since the converting an integer to a double should give a number with no fractional part. It is likely that the operation that generated the value to be passed to Math.ceil was intended to be performed using double precision floating point arithmetic.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - int value cast to float and then passed to Math.round
This code converts an int value to a float precision floating point number and then passing the result to the Math.round() function, which returns the int/long closest to the argument. This operation should always be a no-op, since the converting an integer to a float should give a number with no fractional part. It is likely that the operation that generated the value to be passed to Math.round was intended to be performed using floating point arithmetic.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Integer multiply of result of integer remainder
The code multiplies the result of an integer remaining by an integer constant. Be sure you don't have your operator precedence confused. For example i % 60 * 1000 is (i % 60) * 1000, not i % (60 * 1000).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Integer remainder modulo 1
Any expression (exp % 1) is guaranteed to always return zero. Did you mean (exp & 1) or (exp % 2) instead?
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Integer shift by an amount not in the range 0..31
The code performs an integer shift by a constant amount outside the range 0..31. The effect of this is to use the lower 5 bits of the integer value to decide how much to shift by. This probably isn't want was expected, and it at least confusing.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Invalid syntax for regular expression
The code here uses a regular expression that is invalid according to the syntax for regular expressions. This statement will throw a PatternSyntaxException when executed.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Invocation of equals() on an array, which is equivalent to ==
This method invokes the .equals(Object o) method on an array. Since arrays do not override the equals method of Object, calling equals on an array is the same as comparing their addresses. To compare the contents of the arrays, use java.util.Arrays.equals(Object[], Object[]).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Invocation of hashCode on an array
The code invokes hashCode on an array. Calling hashCode on
an array returns the same value as System.identityHashCode, and ingores
the contents and length of the array. If you need a hashCode that
depends on the contents of an array
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Invocation of toString on an array
The code invokes toString on an (anonymous) array. Calling toString on an array generates a fairly useless result such as [C@16f0472. Consider using Arrays.toString to convert the array into a readable String that gives the contents of the array. See Programming Puzzlers, chapter 3, puzzle 12.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Invocation of toString on an array
The code invokes toString on an array, which will generate a fairly useless result such as [C@16f0472. Consider using Arrays.toString to convert the array into a readable String that gives the contents of the array. See Programming Puzzlers, chapter 3, puzzle 12.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - JUnit assertion in run method will not be noticed by JUnit
A JUnit assertion is performed in a run method. Failed JUnit assertions just result in exceptions being thrown. Thus, if this exception occurs in a thread other than the thread that invokes the test method, the exception will terminate the thread but not result in the test failing.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - MessageFormat supplied where printf style format expected
A method is called that expects a Java printf format string and a list of arguments. However, the format string doesn't contain any format specifiers (e.g., %s) but does contain message format elements (e.g., {0}). It is likely that the code is supplying a MessageFormat string when a printf-style format string is required. At runtime, all of the arguments will be ignored and the format string will be returned exactly as provided without any formatting.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method assigns boolean literal in boolean expression
This method assigns a literal boolean value (true or false) to a boolean variable inside an if or while expression. Most probably this was supposed to be a boolean comparison using ==, not an assignment using =.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method attempts to access a prepared statement parameter with index 0
A call to a setXXX method of a prepared statement was made where the parameter index is 0. As parameter indexes start at index 1, this is always a mistake.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method attempts to access a result set field with index 0
A call to getXXX or updateXXX methods of a result set was made where the field index is 0. As ResultSet fields start at index 1, this is always a mistake.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method call passes null for nonnull parameter
A possibly-null value is passed at a call site where all known target methods require the parameter to be nonnull. Either the parameter is annotated as a parameter that should always be nonnull, or analysis has shown that it will always be dereferenced.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method call passes null for nonnull parameter
This method call passes a null value for a nonnull method parameter. Either the parameter is annotated as a parameter that should always be nonnull, or analysis has shown that it will always be dereferenced.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method call passes null to a nonnull parameter
This method passes a null value as the parameter of a method which must be nonnull. Either this parameter has been explicitly marked as @Nonnull, or analysis has determined that this parameter is always dereferenced.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method defines a variable that obscures a field
This 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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method does not check for null argument
A parameter to this method has been identified as a value that should always be checked to see whether or not it is null, but it is being dereferenced without a preceding null check.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method doesn't override method in superclass due to wrong package for parameter
The method in the subclass doesn't override a similar method in a superclass because the type of a parameter doesn't exactly match the type of the corresponding parameter in the superclass. For example, if you have:
The
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method ignores return value
The return value of this method should be checked. One common cause of this warning is to invoke a method on an immutable object, thinking that it updates the object. For example, in the following code fragment, String dateString = getHeaderField(name); dateString.trim(); the programmer seems to be thinking that the trim() method will update the String referenced by dateString. But since Strings are immutable, the trim() function returns a new String value, which is being ignored here. The code should be corrected to: String dateString = getHeaderField(name); dateString = dateString.trim();
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method ignores return value
The return value of this method should be checked. One common cause of this warning is to invoke a method on an immutable object, thinking that it updates the object. For example, in the following code fragment, String dateString = getHeaderField(name); dateString.trim(); the programmer seems to be thinking that the trim() method will update the String referenced by dateString. But since Strings are immutable, the trim() function returns a new String value, which is being ignored here. The code should be corrected to: String dateString = getHeaderField(name); dateString = dateString.trim();
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method may return null, but is declared @NonNull
This method may return a null value, but the method (or a superclass method which it overrides) is declared to return @NonNull.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method must be private in order for serialization to work
This class implements the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Method performs math using floating point precision
The method performs math operations using floating point precision. Floating point precision is very imprecise. For example, 16777216.0f + 1.0f = 16777216.0f. Consider using double math instead.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - More arguments are passed that are actually used in the format string
A format-string method with a variable number of arguments is called, but more arguments are passed than are actually used by the format string. This won't cause a runtime exception, but the code may be silently omitting information that was intended to be included in the formatted string.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - No previous argument for format string
The format string specifies a relative index to request that the argument for the previous format specifier be reused. However, there is no previous argument. For example,
would throw a MissingFormatArgumentException when executed.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - No relationship between generic parameter and method argument
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 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
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Non-virtual method call passes null for nonnull parameter
A possibly-null value is passed to a nonnull method parameter. Either the parameter is annotated as a parameter that should always be nonnull, or analysis has shown that it will always be dereferenced.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Nonsensical self computation involving a field (e.g., x & x)
This method performs a nonsensical computation of a field with another reference to the same field (e.g., x&x or x-x). Because of the nature of the computation, this operation doesn't seem to make sense, and may indicate a typo or a logic error. Double check the computation.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Nonsensical self computation involving a variable (e.g., x & x)
This method performs a nonsensical computation of a local variable with another reference to the same variable (e.g., x&x or x-x). Because of the nature of the computation, this operation doesn't seem to make sense, and may indicate a typo or a logic error. Double check the computation.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Null pointer dereference
A null pointer is dereferenced here. This will lead to a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Null pointer dereference in method on exception path
A pointer which is null on an exception path is dereferenced here.
This will lead to a Also note that FindBugs considers the default case of a switch statement to be an exception path, since the default case is often infeasible.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Null value is guaranteed to be dereferenced
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).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Nullcheck of value previously dereferenced
A value is checked here to see whether it is null, but this value can't be null because it was previously dereferenced and if it were null a null pointer exception would have occurred at the earlier dereference. Essentially, this code and the previous dereference disagree as to whether this value is allowed to be null. Either the check is redundant or the previous dereference is erroneous.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Number of format-string arguments does not correspond to number of placeholders
A format-string method with a variable number of arguments is called, but the number of arguments passed does not match with the number of % placeholders in the format string. This is probably not what the author intended.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Overwritten increment
The code performs an increment operation (e.g.,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Possible null pointer dereference
There is a branch of statement that, if executed, guarantees that
a null value will be dereferenced, which
would generate a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Possible null pointer dereference in method on exception path
A reference value which is null on some exception control path is
dereferenced here. This may lead to a Also note that FindBugs considers the default case of a switch statement to be an exception path, since the default case is often infeasible.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Primitive array passed to function expecting a variable number of object arguments
This code passes a primitive array to a function that takes a variable number of object arguments. This creates an array of length one to hold the primitive array and passes it to the function.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Primitive value is unboxed and coerced for ternary operator
A wrapped primitive value is unboxed and converted to another primitive type as part of the
evaluation of a conditional ternary operator (the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Random value from 0 to 1 is coerced to the integer 0
A random value from 0 to 1 is being coerced to the integer value 0. You probably
want to multiple the random value by something else before coercing it to an integer, or use the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Read of unwritten field
The program is dereferencing a field that does not seem to ever have a non-null value written to it. Dereferencing this value will generate a null pointer exception.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Repeated conditional tests
The code contains a conditional test is performed twice, one right after the other
(e.g.,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Return value of putIfAbsent ignored, value passed to putIfAbsent reused
The putIfAbsent method is typically used to ensure that a single value is associated with a given key (the first value for which put if absent succeeds). If you ignore the return value and retain a reference to the value passed in, you run the risk of retaining a value that is not the one that is associated with the key in the map. If it matters which one you use and you use the one that isn't stored in the map, your program will behave incorrectly.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Self assignment of field
This method contains a self assignment of a field; e.g.
int x;
public void foo() {
x = x;
}
Such assignments are useless, and may indicate a logic error or typo.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Self comparison of field with itself
This method compares a field with itself, and may indicate a typo or a logic error. Make sure that you are comparing the right things.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Self comparison of value with itself
This method compares a local variable with itself, and may indicate a typo or a logic error. Make sure that you are comparing the right things.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Signature declares use of unhashable class in hashed construct
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Static Thread.interrupted() method invoked on thread instance
This method invokes the Thread.interrupted() method on a Thread object that appears to be a Thread object that is not the current thread. As the interrupted() method is static, the interrupted method will be called on a different object than the one the author intended.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Store of null value into field annotated NonNull
A value that could be null is stored into a field that has been annotated as NonNull.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Suspicious reference comparison of Boolean values
This method compares two Boolean values using the == or != operator. Normally, there are only two Boolean values (Boolean.TRUE and Boolean.FALSE), but it is possible to create other Boolean objects using the new Boolean(b) constructor. It is best to avoid such objects, but if they do exist, then checking Boolean objects for equality using == or != will give results than are different than you would get using .equals(...)
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Suspicious reference comparison to constant
This method compares a reference value to a constant using the == or != operator, where the correct way to compare instances of this type is generally with the equals() method. It is possible to create distinct instances that are equal but do not compare as == since they are different objects. Examples of classes which should generally not be compared by reference are java.lang.Integer, java.lang.Float, etc.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - TestCase declares a bad suite method
Class is a JUnit TestCase and defines a suite() method. However, the suite method needs to be declared as either public static junit.framework.Test suite()or public static junit.framework.TestSuite suite()
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - TestCase defines setUp that doesn't call super.setUp()
Class is a JUnit TestCase and implements the setUp method. The setUp method should call super.setUp(), but doesn't.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - TestCase defines tearDown that doesn't call super.tearDown()
Class is a JUnit TestCase and implements the tearDown method. The tearDown method should call super.tearDown(), but doesn't.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - TestCase has no tests
Class is a JUnit TestCase but has not implemented any test methods
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - TestCase implements a non-static suite method
Class is a JUnit TestCase and implements the suite() method. The suite method should be declared as being static, but isn't.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - The readResolve method must not be declared as a static method.
In order for the readResolve method to be recognized by the serialization mechanism, it must not be declared as a static method.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - The type of a supplied argument doesn't match format specifier
One of the arguments is uncompatible with the corresponding format string specifier.
As a result, this will generate a runtime exception when executed.
For example,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Uncallable method defined in anonymous class
This anonymous class defined a method that is not directly invoked and does not override a method in a superclass. Since methods in other classes cannot directly invoke methods declared in an anonymous class, it seems that this method is uncallable. The method might simply be dead code, but it is also possible that the method is intended to override a method declared in a superclass, and due to an typo or other error the method does not, in fact, override the method it is intended to.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Uninitialized read of field in constructor
This constructor reads a field which has not yet been assigned a value. This is often caused when the programmer mistakenly uses the field instead of one of the constructor's parameters.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Uninitialized read of field method called from constructor of superclass
This method is invoked in the constructor of of the superclass. At this point, the fields of the class have not yet initialized. To make this more concrete, consider the following classes:
abstract class A {
int hashCode;
abstract Object getValue();
A() {
hashCode = getValue().hashCode();
}
}
class B extends A {
Object value;
B(Object v) {
this.value = v;
}
Object getValue() {
return value;
}
}
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Unnecessary type check done using instanceof operator
Type check performed using the instanceof operator where it can be statically determined whether the object is of the type requested.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Unneeded use of currentThread() call, to call interrupted()
This method invokes the Thread.currentThread() call, just to call the interrupted() method. As interrupted() is a static method, is more simple and clear to use Thread.interrupted().
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Unwritten field
This field is never written. All reads of it will return the default value. Check for errors (should it have been initialized?), or remove it if it is useless.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Use of class without a hashCode() method in a hashed data structure
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Useless assignment in return statement
This statement assigns to a local variable in a return statement. This assignment has effect. Please verify that this statement does the right thing.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Useless control flow to next line
This method contains a useless control flow statement in which control
flow follows to the same or following line regardless of whether or not
the branch is taken.
Often, this is caused by inadvertently using an empty statement as the
body of an
if (argv.length == 1);
System.out.println("Hello, " + argv[0]);
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Using pointer equality to compare different types
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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Vacuous call to collections
This call doesn't make sense. For any collection
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Value annotated as carrying a type qualifier used where a value that must not carry that qualifier is required
A value specified as carrying a type qualifier annotation is consumed in a location or locations requiring that the value not carry that annotation. More precisely, a value annotated with a type qualifier specifying when=ALWAYS is guaranteed to reach a use or uses where the same type qualifier specifies when=NEVER. For example, say that @NonNegative is a nickname for the type qualifier annotation @Negative(when=When.NEVER). The following code will generate this warning because the return statement requires a @NonNegative value, but receives one that is marked as @Negative.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Value annotated as never carrying a type qualifier used where value carrying that qualifier is required
A value specified as not carrying a type qualifier annotation is guaranteed to be consumed in a location or locations requiring that the value does carry that annotation. More precisely, a value annotated with a type qualifier specifying when=NEVER is guaranteed to reach a use or uses where the same type qualifier specifies when=ALWAYS. TODO: example
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Value is null and guaranteed to be dereferenced 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).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Value that might carry a type qualifier is always used in a way prohibits it from having that type qualifier
A value that is annotated as possibility being an instance of the values denoted by the type qualifier, and the value is guaranteed to be used in a way that prohibits values denoted by that type qualifier.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Value that might not carry a type qualifier is always used in a way requires that type qualifier
A value that is annotated as possibility not being an instance of the values denoted by the type qualifier, and the value is guaranteed to be used in a way that requires values denoted by that type qualifier.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Correctness - Very confusing method names
The referenced methods have names that differ only by capitalization. This is very confusing because if the capitalization were identical then one of the methods would override the other.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Cyclomatic Complexity
Checks cyclomatic complexity of methods against a specified limit. The complexity is measured by the number of if, while, do, for, ?:, catch, switch, case statements, and operators && and || (plus one) in the body of a constructor, method, static initializer, or instance initializer. It is a measure of the minimum number of possible paths through the source and therefore the number of required tests. Generally 1-4 is considered good, 5-7 ok, 8-10 consider re-factoring, and 11+ re-factor now !
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Default Comes Last
Check that the default is after all the cases in a switch statement.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Ambiguous invocation of either an inherited or outer method
An inner class is invoking a method that could be resolved to either a inherited method or a method defined in an outer class. By the Java semantics, it will be resolved to invoke the inherited method, but this may not be want you intend. If you really intend to invoke the inherited method, invoke it by invoking the method on super (e.g., invoke super.foo(17)), and thus it will be clear to other readers of your code and to FindBugs that you want to invoke the inherited method, not the method in the outer class.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Call to unsupported method
All targets of this method invocation throw an UnsupportedOperationException.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Check for oddness that won't work for negative numbers
The code uses x % 2 == 1 to check to see if a value is odd, but this won't work for negative numbers (e.g., (-5) % 2 == -1). If this code is intending to check for oddness, consider using x & 1 == 1, or x % 2 != 0.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Class exposes synchronization and semaphores in its public interface
This class uses synchronization along with wait(), notify() or notifyAll() on itself (the this reference). Client classes that use this class, may, in addition, use an instance of this class as a synchronizing object. Because two classes are using the same object for synchronization, Multithread correctness is suspect. You should not synchronize nor call semaphore methods on a public reference. Consider using a internal private member variable to control synchronization.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Class extends Servlet class and uses instance variables
This class extends from a Servlet class, and uses an instance member variable. Since only one instance of a Servlet class is created by the J2EE framework, and used in a multithreaded way, this paradigm is highly discouraged and most likely problematic. Consider only using method local variables.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Class extends Struts Action class and uses instance variables
This class extends from a Struts Action class, and uses an instance member variable. Since only one instance of a struts Action class is created by the Struts framework, and used in a multithreaded way, this paradigm is highly discouraged and most likely problematic. Consider only using method local variables. Only instance fields that are written outside of a monitor are reported.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Class implements same interface as superclass
This class declares that it implements an interface that is also implemented by a superclass. This is redundant because once a superclass implements an interface, all subclasses by default also implement this interface. It may point out that the inheritance hierarchy has changed since this class was created, and consideration should be given to the ownership of the interface's implementation.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Class is final but declares protected field
This class is declared to be final, but declares fields to be protected. Since the class is final, it can not be derived from, and the use of protected is confusing. The access modifier for the field should be changed to private or public to represent the true use for the field.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Class too big for analysis
This class is bigger than can be effectively handled, and was not fully analyzed for errors.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Code contains a hard coded reference to an absolute pathname
This code constructs a File object using a hard coded to an absolute pathname
(e.g.,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Complicated, subtle or wrong increment in for-loop
Are you sure this for loop is incrementing the correct variable? It appears that another variable is being initialized and checked by the for loop.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Computation of average could overflow
The code computes the average of two integers using either division or signed right shift,
and then uses the result as the index of an array.
If the values being averaged are very large, this can overflow (resulting in the computation
of a negative average). Assuming that the result is intended to be nonnegative, you
can use an unsigned right shift instead. In other words, rather that using This bug exists in many earlier implementations of binary search and merge sort. Martin Buchholz found and fixed it in the JDK libraries, and Joshua Bloch widely publicized the bug pattern.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Consider returning a zero length array rather than null
It is often a better design to return a length zero array rather than a null reference to indicate that there are no results (i.e., an empty list of results). This way, no explicit check for null is needed by clients of the method. On the other hand, using null to indicate
"there is no answer to this question" is probably appropriate.
For example,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Dead store of null to local variable
The code stores null into a local variable, and the stored value is not read. This store may have been introduced to assist the garbage collector, but as of Java SE 6.0, this is no longer needed or useful.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Dead store to local variable
This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used. Note that Sun's javac compiler often generates dead stores for final local variables. Because FindBugs is a bytecode-based tool, there is no easy way to eliminate these false positives.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Dereference of the result of readLine() without nullcheck
The result of invoking readLine() is dereferenced without checking to see if the result is null. If there are no more lines of text to read, readLine() will return null and dereferencing that will generate a null pointer exception.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Double assignment of local variable
This method contains a double assignment of a local variable; e.g.
public void foo() {
int x,y;
x = x = 17;
}
Assigning the same value to a variable twice is useless, and may indicate a logic error or typo.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Exception is caught when Exception is not thrown
This method uses a try-catch block that catches Exception objects, but Exception is not thrown within the try block, and RuntimeException is not explicitly caught. It is a common bug pattern to say try { ... } catch (Exception e) { something } as a shorthand for catching a number of types of exception each of whose catch blocks is identical, but this construct also accidentally catches RuntimeException as well, masking potential bugs.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Immediate dereference of the result of readLine()
The result of invoking readLine() is immediately dereferenced. If there are no more lines of text to read, readLine() will return null and dereferencing that will generate a null pointer exception.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Initialization circularity
A 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.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - instanceof will always return true
This instanceof test will always return true (unless the value being tested is null). Although this is safe, make sure it isn't an indication of some misunderstanding or some other logic error. If you really want to test the value for being null, perhaps it would be clearer to do better to do a null test rather than an instanceof test.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - int division result cast to double or float
This code casts the result of an integer division operation to double or float. Doing division on integers truncates the result to the integer value closest to zero. The fact that the result was cast to double suggests that this precision should have been retained. What was probably meant was to cast one or both of the operands to double before performing the division. Here is an example: int x = 2; int y = 5; // Wrong: yields result 0.0 double value1 = x / y; // Right: yields result 0.4 double value2 = x / (double) y;
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Invocation of substring(0), which returns the original value
This code invokes substring(0) on a String, which returns the original value.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Load of known null value
The variable referenced at this point is known to be null due to an earlier check against null. Although this is valid, it might be a mistake (perhaps you intended to refer to a different variable, or perhaps the earlier check to see if the variable is null should have been a check to see if it was nonnull).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Method checks to see if result of String.indexOf is positive
The method invokes String.indexOf and checks to see if the result is positive or non-positive. It is much more typical to check to see if the result is negative or non-negative. It is positive only if the substring checked for occurs at some place other than at the beginning of the String.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Method directly allocates a specific implementation of xml interfaces
This method allocates a specific implementation of an xml interface. It is preferable to use the supplied factory classes to create these objects so that the implementation can be changed at runtime. See
for details.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Method discards result of readLine after checking if it is nonnull
The value returned by readLine is discarded after checking to see if the return value is non-null. In almost all situations, if the result is non-null, you will want to use that non-null value. Calling readLine again will give you a different line.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Method uses the same code for two branches
This method uses the same code to implement two branches of a conditional branch. Check to ensure that this isn't a coding mistake.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Method uses the same code for two switch clauses
This method uses the same code to implement two clauses of a switch statement. This could be a case of duplicate code, but it might also indicate a coding mistake.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Non serializable object written to ObjectOutput
This code seems to be passing a non-serializable object to the ObjectOutput.writeObject method. If the object is, indeed, non-serializable, an error will result.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Non-Boolean argument formatted using %b format specifier
An argument not of type Boolean is being formatted with a %b format specifier. This won't throw an exception; instead, it will print true for any nonnull value, and false for null. This feature of format strings is strange, and may not be what you intended.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Parameter must be nonnull but is marked as nullable
This parameter is always used in a way that requires it to be nonnull, but the parameter is explicitly annotated as being Nullable. Either the use of the parameter or the annotation is wrong.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Possible null pointer dereference due to return value of called method
The return value from a method is dereferenced without a null check,
and the return value of that method is one that should generally be checked
for null. This may lead to a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Possible null pointer dereference on path that might be infeasible
There is a branch of statement that, if executed, guarantees that
a null value will be dereferenced, which
would generate a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Potentially dangerous use of non-short-circuit logic
This code seems to be using non-short-circuit logic (e.g., & or |) rather than short-circuit logic (&& or ||). In addition, it seem possible that, depending on the value of the left hand side, you might not want to evaluate the right hand side (because it would have side effects, could cause an exception or could be expensive. Non-short-circuit logic causes both sides of the expression to be evaluated even when the result can be inferred from knowing the left-hand side. This can be less efficient and can result in errors if the left-hand side guards cases when evaluating the right-hand side can generate an error. See the Java Language Specification for details
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - private readResolve method not inherited by subclasses
This class defines a private readResolve method. Since it is private, it won't be inherited by subclasses. This might be intentional and OK, but should be reviewed to ensure it is what is intended.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Questionable cast to abstract collection
This code casts a Collection to an abstract collection
(such as
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Questionable cast to concrete collection
This code casts an abstract collection (such as a Collection, List, or Set) to a specific concrete implementation (such as an ArrayList or HashSet). This might not be correct, and it may make your code fragile, since it makes it harder to switch to other concrete implementations at a future point. Unless you have a particular reason to do so, just use the abstract collection class.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Questionable use of non-short-circuit logic
This code seems to be using non-short-circuit logic (e.g., & or |) rather than short-circuit logic (&& or ||). Non-short-circuit logic causes both sides of the expression to be evaluated even when the result can be inferred from knowing the left-hand side. This can be less efficient and can result in errors if the left-hand side guards cases when evaluating the right-hand side can generate an error. See the Java Language Specification for details
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Redundant comparison of non-null value to null
This method contains a reference known to be non-null with another reference known to be null.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Redundant comparison of two null values
This method contains a redundant comparison of two references known to both be definitely null.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Redundant nullcheck of value known to be non-null
This method contains a redundant check of a known non-null value against the constant null.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Redundant nullcheck of value known to be null
This method contains a redundant check of a known null value against the constant null.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Remainder of 32-bit signed random integer
This code generates a random signed integer and then computes the remainder of that value modulo another value. Since the random number can be negative, the result of the remainder operation can also be negative. Be sure this is intended, and strongly consider using the Random.nextInt(int) method instead.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Remainder of hashCode could be negative
This code computes a hashCode, and then computes the remainder of that value modulo another value. Since the hashCode can be negative, the result of the remainder operation can also be negative. Assuming you want to ensure that the result of your computation is nonnegative,
you may need to change your code.
If you know the divisor is a power of 2,
you can use a bitwise and operator instead (i.e., instead of
using
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Result of integer multiplication cast to long
This code performs integer multiply and then converts the result to a long,
as in:
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Self assignment of local variable
This method contains a self assignment of a local variable; e.g.
public void foo() {
int x = 3;
x = x;
}
Such assignments are useless, and may indicate a logic error or typo.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Test for floating point equality
This operation compares two floating point values for equality.
Because floating point calculations may involve rounding,
calculated float and double values may not be accurate.
For values that must be precise, such as monetary values,
consider using a fixed-precision type such as BigDecimal.
For values that need not be precise, consider comparing for equality
within some range, for example:
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Thread passed where Runnable expected
A Thread object is passed as a parameter to a method where a Runnable is expected. This is rather unusual, and may indicate a logic error or cause unexpected behavior.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Transient field of class that isn't Serializable.
The field is marked as transient, but the class isn't Serializable, so marking it as transient has absolutely no effect. This may be leftover marking from a previous version of the code in which the class was transient, or it may indicate a misunderstanding of how serialization works.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Unchecked/unconfirmed cast
This cast is unchecked, and not all instances of the type casted from can be cast to the type it is being cast to. Ensure that your program logic ensures that this cast will not fail.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Unsigned right shift cast to short/byte
The code performs an unsigned right shift, whose result is then cast to a short or byte, which discards the upper bits of the result. Since the upper bits are discarded, there may be no difference between a signed and unsigned right shift (depending upon the size of the shift).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Unusual equals method
This class doesn't do any of the patterns we recognize for checking that the type of the argument
is compatible with the type of the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Useless control flow
This method contains a useless control flow statement, where
control flow continues onto the same place regardless of whether or not
the branch is taken. For example,
this is caused by having an empty statement
block for an
if (argv.length == 0) {
// TODO: handle this case
}
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Vacuous bit mask operation on integer value
This is an integer bit operation (and, or, or exclusive or) that doesn't do any useful work
(e.g.,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Vacuous comparison of integer value
There is an integer comparison that always returns the same value (e.g., x <= Integer.MAX_VALUE).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dodgy - Write to static field from instance method
This instance method writes to a static field. This is tricky to get correct if multiple instances are being manipulated, and generally bad practice.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dont Import Java Lang
Avoid importing anything from the package 'java.lang'. These classes are automatically imported (JLS 7.5.3).
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Dont Import Sun
Avoid importing anything from the 'sun.*' packages. These packages are not portable and are likely to change.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Double Checked Locking
Detect the double-checked locking idiom, a technique that tries to avoid synchronization overhead but is incorrect because of subtle artifacts of the java memory model.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Empty Finalizer
If the finalize() method is empty, then it does not need to exist.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Empty Finally Block
Avoid empty finally blocks - these can be deleted.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Empty If Stmt
Empty If Statement finds instances where a condition is checked but nothing is done about it.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Empty Statement
Detects empty statements (standalone ';').
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Empty Static Initializer
An empty static initializer was found.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Empty Switch Statements
Avoid empty switch statements.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Empty Synchronized Block
Avoid empty synchronized blocks - they're useless.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Empty Try Block
Avoid empty try blocks - what's the point?
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Empty While Stmt
Empty While Statement finds all instances where a while statement does nothing. If it is a timing loop, then you should use Thread.sleep() for it; if it's a while loop that does a lot in the exit expression, rewrite it to make it clearer.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Equals Hash Code
Checks that classes that override equals() also override hashCode().
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Equals Null
Inexperienced programmers sometimes confuse comparison concepts and use equals() to compare to null.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Exception As Flow Control
Using Exceptions as flow control leads to GOTOish code and obscures true exceptions when debugging.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Experimental - Potential lost logger changes due to weak reference in OpenJDK
OpenJDK introduces a potential incompatibility. In particular, the java.util.logging.Logger behavior has changed. Instead of using strong references, it now uses weak references internally. That's a reasonable change, but unfortunately some code relies on the old behavior - when changing logger configuration, it simply drops the logger reference. That means that the garbage collector is free to reclaim that memory, which means that the logger configuration is lost. For example, consider: public static void initLogging() throws Exception {
Logger logger = Logger.getLogger("edu.umd.cs");
logger.addHandler(new FileHandler()); // call to change logger configuration
logger.setUseParentHandlers(false); // another call to change logger configuration
}
The logger reference is lost at the end of the method (it doesn't escape the method), so if you have a garbage collection cycle just after the call to initLogging, the logger configuration is lost (because Logger only keeps weak references). public static void main(String[] args) throws Exception {
initLogging(); // adds a file handler to the logger
System.gc(); // logger configuration lost
Logger.getLogger("edu.umd.cs").info("Some message"); // this isn't logged to the file as expected
}
Ulf Ochsenfahrt and Eric Fellheimer
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Final Class
Checks that class which has only private constructors is declared as final.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Final Field Could Be Static
If a final field is assigned to a compile-time constant, it could be made static, thus saving overhead in each object at runtime.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Finalize Does Not Call Super Finalize
If the finalize() is implemented, its last action should be to call super.finalize.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Finalize Overloaded
Methods named finalize() should not have parameters. It is confusing and probably a bug to overload finalize(). It will not be called by the VM.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
For Loops Must Use Braces
Avoid using 'for' statements without using curly braces, like
for (int i=0; i<42;i++) foo();
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hidden Field
Checks that a local variable or a parameter does not shadow a field that is defined in the same class.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hide Utility Class Constructor
Make sure that utility classes (classes that contain only static methods) do not have a public constructor.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Idempotent Operations
Avoid idempotent operations - they are have no effect. Example :
int x = 2;
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
If Else Stmts Must Use Braces
Avoid using if..else statements without using curly braces.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
If Stmts Must Use Braces
Avoid using if statements without using curly braces.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Illegal Throws
Throwing java.lang.Error or java.lang.RuntimeException is almost never acceptable.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inefficient String Buffering
Avoid concatenating non literals in a StringBuffer constructor or append().
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Instantiation To Get Class
Avoid instantiating an object just to call getClass() on it; use the .class public member instead. Example : replace
Class c = new String().getClass(); with Class c = String.class;
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Integer Instantiation
In JDK 1.5, calling new Integer() causes memory allocation. Integer.valueOf() is more memory friendly.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Local Final Variable Name
Checks that local final variable names, including catch parameters, conform to the specified format
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Local Variable Name
Checks that local, non-final variable names conform to the specified format
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Loose coupling
Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Magic Number
Checks for magic numbers.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Malicious code vulnerability - Field is a mutable array
A final static field references an array and can be accessed by malicious code or by accident from another package. This code can freely modify the contents of the array.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Malicious code vulnerability - Field is a mutable Hashtable
A final static field references a Hashtable and can be accessed by malicious code or by accident from another package. This code can freely modify the contents of the Hashtable.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Malicious code vulnerability - Field isn't final and can't be protected from malicious code
A mutable static field could be changed by malicious code or by accident from another package. Unfortunately, the way the field is used doesn't allow any easy fix to this problem.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Malicious code vulnerability - Field isn't final but should be
A mutable static field could be changed by malicious code or by accident from another package. The field could be made final to avoid this vulnerability.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Malicious code vulnerability - Field should be both final and package protected
A mutable static field could be changed by malicious code or by accident from another package. The field could be made package protected and/or made final to avoid this vulnerability.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Malicious code vulnerability - Field should be moved out of an interface and made package protected
A final static field that is defined in an interface references a mutable object such as an array or hashtable. This mutable object could be changed by malicious code or by accident from another package. To solve this, the field needs to be moved to a class and made package protected to avoid this vulnerability.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Malicious code vulnerability - Field should be package protected
A mutable static field could be changed by malicious code or by accident. The field could be made package protected to avoid this vulnerability.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Malicious code vulnerability - Finalizer should be protected, not public
A class's
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Malicious code vulnerability - May expose internal static state by storing a mutable object into a static field
This code stores a reference to an externally mutable object into a static field. If unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Storing a copy of the object is better approach in many situations.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Malicious code vulnerability - Public static method may expose internal representation by returning array
A public static method returns a reference to an array that is part of the static state of the class. Any code that calls this method can freely modify the underlying array. One fix is to return a copy of the array.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member name
Checks that name of non-static fields conform to the specified format
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Method Name
Checks that method names conform to the specified format
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Missing Static Method In Non Instantiatable Class
A class that has private constructors and does not have any static methods or fields cannot be used.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Modifier Order
Checks that the order of modifiers conforms to the suggestions in the Java Language specification, sections 8.1.1, 8.3.1 and 8.4.3. The correct order is : public, protected, private, abstract, static, final, transient, volatile, synchronized, native, strictfp.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - A thread was created using the default empty run method
This method creates a thread without specifying a run method either by deriving from the Thread class, or by passing a Runnable object. This thread, then, does nothing but waste time.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - A volatile reference to an array doesn't treat the array elements as volatile
This declares a volatile reference to an array, which might not be what you want. With a volatile reference to an array, reads and writes of the reference to the array are treated as volatile, but the array elements are non-volatile. To get volatile array elements, you will need to use one of the atomic array classes in java.util.concurrent (provided in Java 5.0).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Call to static Calendar
Even though the JavaDoc does not contain a hint about it, Calendars are inherently unsafe for multihtreaded use. The detector has found a call to an instance of Calendar that has been obtained via a static field. This looks suspicous. For more information on this see Sun Bug #6231579 and Sun Bug #6178997.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Call to static DateFormat
As the JavaDoc states, DateFormats are inherently unsafe for multithreaded use. The detector has found a call to an instance of DateFormat that has been obtained via a static field. This looks suspicous. For more information on this see Sun Bug #6231579 and Sun Bug #6178997.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Class's readObject() method is synchronized
This serializable class defines a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Class's writeObject() method is synchronized but nothing else is
This class has a
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Condition.await() not in loop
This method contains a call to
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Constructor invokes Thread.start()
The constructor starts a thread. This is likely to be wrong if the class is ever extended/subclassed, since the thread will be started before the subclass constructor is started.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Empty synchronized block
The code contains an empty synchronized block:
synchronized() {}
Empty synchronized blocks are far more subtle and hard to use correctly than most people recognize, and empty synchronized blocks are almost never a better solution than less contrived solutions.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Field not guarded against concurrent access
This field is annotated with net.jcip.annotations.GuardedBy, but can be accessed in a way that seems to violate the annotation.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Inconsistent synchronization
The fields of this class appear to be accessed inconsistently with respect to synchronization. This bug report indicates that the bug pattern detector judged that
A typical bug matching this bug pattern is forgetting to synchronize one of the methods in a class that is intended to be thread-safe. Note that there are various sources of inaccuracy in this detector; for example, the detector cannot statically detect all situations in which a lock is held. Also, even when the detector is accurate in distinguishing locked vs. unlocked accesses, the code in question may still be correct.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Inconsistent synchronization
The fields of this class appear to be accessed inconsistently with respect to synchronization. This bug report indicates that the bug pattern detector judged that
A typical bug matching this bug pattern is forgetting to synchronize one of the methods in a class that is intended to be thread-safe. You can select the nodes labeled "Unsynchronized access" to show the code locations where the detector believed that a field was accessed without synchronization. Note that there are various sources of inaccuracy in this detector; for example, the detector cannot statically detect all situations in which a lock is held. Also, even when the detector is accurate in distinguishing locked vs. unlocked accesses, the code in question may still be correct.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Incorrect lazy initialization and update of static field
This method contains an unsynchronized lazy initialization of a static field. After the field is set, the object stored into that location is further accessed. The setting of the field is visible to other threads as soon as it is set. If the futher accesses in the method that set the field serve to initialize the object, then you have a very serious multithreading bug, unless something else prevents any other thread from accessing the stored object until it is fully initialized.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Incorrect lazy initialization of static field
This method contains an unsynchronized lazy initialization of a non-volatile static field. Because the compiler or processor may reorder instructions, threads are not guaranteed to see a completely initialized object, if the method can be called by multiple threads. You can make the field volatile to correct the problem. For more information, see the Java Memory Model web site.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Invokes run on a thread (did you mean to start it instead?)
This method explicitly invokes
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Method calls Thread.sleep() with a lock held
This method calls Thread.sleep() with a lock held. This may result in very poor performance and scalability, or a deadlock, since other threads may be waiting to acquire the lock. It is a much better idea to call wait() on the lock, which releases the lock and allows other threads to run.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Method does not release lock on all exception paths
This method acquires a JSR-166 (
Lock l = ...;
l.lock();
try {
// do something
} finally {
l.unlock();
}
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Method does not release lock on all paths
This method acquires a JSR-166 (
Lock l = ...;
l.lock();
try {
// do something
} finally {
l.unlock();
}
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Method spins on field
This method spins in a loop which reads a field. The compiler may legally hoist the read out of the loop, turning the code into an infinite loop. The class should be changed so it uses proper synchronization (including wait and notify calls).
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Method synchronizes on an updated field
This method synchronizes on an object referenced from a mutable field. This is unlikely to have useful semantics, since different threads may be synchronizing on different objects.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Mismatched notify()
This method calls Object.notify() or Object.notifyAll() without obviously holding a lock
on the object. Calling notify() or notifyAll() without a lock held will result in
an
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Mismatched wait()
This method calls Object.wait() without obviously holding a lock
on the object. Calling wait() without a lock held will result in
an
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Monitor wait() called on Condition
This method calls
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Mutable servlet field
A web server generally only creates one instance of servlet or jsp class (i.e., treats the class as a Singleton), and will have multiple threads invoke methods on that instance to service multiple simultaneous requests. Thus, having a mutable instance field generally creates race conditions.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Naked notify
A call to This bug does not necessarily indicate an error, since the change to mutable object state may have taken place in a method which then called the method containing the notification.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Possible double check of field
This method may contain an instance of double-checked locking. This idiom is not correct according to the semantics of the Java memory model. For more information, see the web page http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Static Calendar
Even though the JavaDoc does not contain a hint about it, Calendars are inherently unsafe for multihtreaded use. Sharing a single instance across thread boundaries without proper synchronization will result in erratic behavior of the application. Under 1.4 problems seem to surface less often than under Java 5 where you will probably see random ArrayIndexOutOfBoundsExceptions or IndexOutOfBoundsExceptions in sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(). You may also experience serialization problems. Using an instance field is recommended. For more information on this see Sun Bug #6231579 and Sun Bug #6178997.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Static DateFormat
As the JavaDoc states, DateFormats are inherently unsafe for multithreaded use. Sharing a single instance across thread boundaries without proper synchronization will result in erratic behavior of the application. You may also experience serialization problems. Using an instance field is recommended. For more information on this see Sun Bug #6231579 and Sun Bug #6178997.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Sychronization on getClass rather than class literal
This instance method synchronizes on
private static final String base = "label";
private static int nameCounter = 0;
String constructComponentName() {
synchronized (getClass()) {
return base + nameCounter++;
}
}
Subclasses of
private static final String base = "label";
private static int nameCounter = 0;
String constructComponentName() {
synchronized (Label.class) {
return base + nameCounter++;
}
}
Bug pattern contributed by Jason Mehrens
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Synchronization on Boolean could lead to deadlock
The code synchronizes on a boxed primitive constant, such as an Boolean.
private static Boolean inited = Boolean.FALSE;
...
synchronized(inited) {
if (!inited) {
init();
inited = Boolean.TRUE;
}
}
...
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
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Synchronization on boxed primitive could lead to deadlock
The code synchronizes on a boxed primitive constant, such as an Integer.
private static Integer count = 0;
...
synchronized(count) {
count++;
}
...
Since Integer objects can be cached and shared, this code could be synchronizing on the same object as other, unrelated code, leading to unresponsiveness and possible deadlock
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Synchronization on boxed primitive values
The code synchronizes on an apparently unshared boxed primitive, such as an Integer.
private static final Integer fileLock = new Integer(1);
...
synchronized(fileLock) {
.. do something ..
}
...
It would be much better, in this code, to redeclare fileLock as private static final Object fileLock = new Object();The existing code might be OK, but it is confusing and a future refactoring, such as the "Remove Boxing" refactoring in IntelliJ, might replace this with the use of an interned Integer object shared throughout the JVM, leading to very confusing behavior and potential deadlock.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Synchronization on field in futile attempt to guard that field
This method synchronizes on a field in what appears to be an attempt to guard against simultaneous updates to that field. But guarding a field gets a lock on the referenced object, not on the field. This may not provide the mutual exclusion you need, and other threads might be obtaining locks on the referenced objects (for other purposes). An example of this pattern would be:
private Long myNtfSeqNbrCounter = new Long(0);
private Long getNotificationSequenceNumber() {
Long result = null;
synchronized(myNtfSeqNbrCounter) {
result = new Long(myNtfSeqNbrCounter.longValue() + 1);
myNtfSeqNbrCounter = new Long(result.longValue());
}
return result;
}
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Synchronization on interned String could lead to deadlock
The code synchronizes on interned String.
private static String LOCK = "LOCK";
...
synchronized(LOCK) { ...}
...
Constant Strings are interned and shared across all other classes loaded by the JVM. Thus, this could is locking on something that other code might also be locking. This could result in very strange and hard to diagnose blocking and deadlock behavior. See http://www.javalobby.org/java/forums/t96352.html and http://jira.codehaus.org/browse/JETTY-352.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Synchronization performed on java.util.concurrent Lock
This method performs synchronization on an implementation of
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Synchronize and null check on the same field.
Since the field is synchronized on, it seems not likely to be null. If it is null and then synchronized on a NullPointerException will be thrown and the check would be pointless. Better to synchronize on another field.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Unconditional wait
This method contains a call to
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Unsynchronized get method, synchronized set method
This class contains similarly-named get and set methods where the set method is synchronized and the get method is not. This may result in incorrect behavior at runtime, as callers of the get method will not necessarily see a consistent state for the object. The get method should be made synchronized.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Using notify() rather than notifyAll()
This method calls
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Wait not in loop
This method contains a call to
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Multithreaded correctness - Wait with two locks held
Waiting on a monitor while two locks are held may cause deadlock. Performing a wait only releases the lock on the object being waited on, not any other locks. This not necessarily a bug, but is worth examining closely.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Naming - Avoid dollar signs
Avoid using dollar signs in variable/method/class/interface names.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Naming - Class naming conventions
Class names should always begin with an upper case character.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Naming - Method with same name as enclosing class
Non-constructor methods should not have the same name as the enclosing class. Example :
public class MyClass {
// this is bad because it is a method
public void MyClass() {}
// this is OK because it is a constructor
public MyClass() {}
}
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Naming - Suspicious constant field name
A field name is all in uppercase characters, which in Sun's Java naming conventions indicate a constant. However, the field is not final. Example :
public class Foo {
// this is bad, since someone could accidentally
// do PI = 2.71828; which is actualy e
// final double PI = 3.16; is ok
double PI = 3.16;
}
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Naming - Suspicious equals method name
The method name and parameter number are suspiciously close to equals(Object), which may mean you are intending to override the equals(Object) method. Example :
public class Foo {
public int equals(Object o) {
// oops, this probably was supposed to be boolean equals
}
public boolean equals(String s) {
// oops, this probably was supposed to be equals(Object)
}
}
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Naming - Suspicious Hashcode method name
The method name and return type are suspiciously close to hashCode(), which may mean you are intending to override the hashCode() method. Example :
public class Foo {
public int hashcode() {
// oops, this probably was supposed to be hashCode
}
}
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ncss Method Count
This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given method. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ncss Type Count
This rule uses the NCSS (Non Commenting Source Statements) algorithm to determine the number of lines of code for a given type. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Package name
Checks that package names conform to the specified format. The default value of format
has been chosen to match the requirements in the Java Language specification and the Sun coding conventions.
However both underscores and uppercase letters are rather uncommon, so most configurations should probably
assign value ^[a-z]+(\.[a-z][a-z0-9]*)*$ to format
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Parameter Assignment
Disallow assignment of parameters.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Parameter Name
Checks that parameter names conform to the specified format
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Could be refactored into a static inner class
This class is an inner class, but does not use its embedded reference to the object which created it except during construction of the inner object. This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary. If possible, the class should be made into a static inner class. Since the reference to the outer object is required during construction of the inner instance, the inner class will need to be refactored so as to pass a reference to the outer instance to the constructor for the inner class.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Explicit garbage collection; extremely dubious except in benchmarking code
Code explicitly invokes garbage collection. Except for specific use in benchmarking, this is very dubious. In the past, situations where people have explicitly invoked the garbage collector in routines such as close or finalize methods has led to huge performance black holes. Garbage collection can be expensive. Any situation that forces hundreds or thousands of garbage collections will bring the machine to a crawl.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Huge string constants is duplicated across multiple class files
A large String constant is duplicated across multiple class files. This is likely because a final field is initialized to a String constant, and the Java language mandates that all references to a final field from other classes be inlined into that classfile. See JDK bug 6447475 for a description of an occurrence of this bug in the JDK and how resolving it reduced the size of the JDK by 1 megabyte.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Inefficient use of keySet iterator instead of entrySet iterator
This method accesses the value of a Map entry, using a key that was retrieved from a keySet iterator. It is more efficient to use an iterator on the entrySet of the map, to avoid the Map.get(key) lookup.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Maps and sets of URLs can be performance hogs
This method or field is or uses a Map or Set of URLs. Since both the equals and hashCode
method of URL perform domain name resolution, this can result in a big performance hit.
See http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html for more information.
Consider using
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Method allocates a boxed primitive just to call toString
A boxed primitive is allocated just to call toString(). It is more effective to just use the static form of toString which takes the primitive value. So,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Method allocates an object, only to get the class object
This method allocates an object just to call getClass() on it, in order to retrieve the Class object for it. It is simpler to just access the .class property of the class.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Method calls static Math class method on a constant value
This method uses a static method from java.lang.Math on a constant value. This method's result in this case, can be determined statically, and is faster and sometimes more accurate to just use the constant. Methods detected are:
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - 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();
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Method invokes inefficient Boolean constructor; use Boolean.valueOf(...) instead
Creating new instances of
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Method invokes inefficient floating-point Number constructor; use static valueOf instead
Using
Unless the class must be compatible with JVMs predating Java 1.5,
use either autoboxing or the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Method invokes inefficient new String() constructor
Creating a new
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Method invokes inefficient new String(String) constructor
Using the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Method invokes inefficient Number constructor; use static valueOf instead
Using
Values between -128 and 127 are guaranteed to have corresponding cached instances
and using
Unless the class must be compatible with JVMs predating Java 1.5,
use either autoboxing or the
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Method invokes toString() method on a String
Calling
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Method uses toArray() with zero-length array argument
This method uses the toArray() method of a collection derived class, and passes
in a zero-length prototype array argument. It is more efficient to use
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Primitive value is boxed and then immediately unboxed
A primitive is boxed, and then immediately unboxed. This probably is due to a manual boxing in a place where an unboxed value is required, thus forcing the compiler to immediately undo the work of the boxing.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Primitive value is boxed then unboxed to perform primitive coercion
A primitive boxed value constructed and then immediately converted into a different primitive type
(e.g.,
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Private method is never called
This private method is never called. Although it is possible that the method will be invoked through reflection, it is more likely that the method is never used, and should be removed.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Should be a static inner class
This class is an inner class, but does not use its embedded reference to the object which created it. This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary. If possible, the class should be made static.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - The equals and hashCode methods of URL are blocking
The equals and hashCode
method of URL perform domain name resolution, this can result in a big performance hit.
See http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html for more information.
Consider using
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Unread field
This field is never read. Consider removing it from the class.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Unread field: should this field be static?
This class contains an instance final field that is initialized to a compile-time static value. Consider making the field static.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Unused field
This field is never used. Consider removing it from the class.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Performance - Use the nextInt method of Random rather than nextDouble to generate a random integer
If
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Preserve Stack Trace
Throwing a new exception from a catch block without passing the original exception into the new Exception will cause the true stack trace to be lost, and can make it difficult to debug effectively.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Redundant Throws
Checks for redundant exceptions declared in throws clause such as duplicates, unchecked exceptions or subclasses of another declared exception.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Replace Enumeration With Iterator
Consider replacing this Enumeration with the newer java.util.Iterator
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Replace Hashtable With Map
Consider replacing this Hashtable with the newer java.util.Map
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Replace Vector With List
Consider replacing Vector usages with the newer java.util.ArrayList if expensive threadsafe operation is not required.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security - A prepared statement is generated from a nonconstant String
The code creates an SQL prepared statement from a nonconstant String. If unchecked, tainted data from a user is used in building this String, SQL injection could be used to make the prepared statement do something unexpected and undesirable.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security - Array is stored directly
Constructors and methods receiving arrays should clone objects and store the copy. This prevents that future changes from the user affect the internal functionality.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security - Empty database password
This code creates a database connect using a blank or empty password. This indicates that the database is not protected by a password.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security - Hardcoded constant database password
This code creates a database connect using a hardcoded, constant password. Anyone with access to either the source code or the compiled code can easily learn the password.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security - HTTP cookie formed from untrusted input
This code constructs an HTTP Cookie using an untrusted HTTP parameter. If this cookie is added to an HTTP response, it will allow a HTTP response splitting vulnerability. See http://en.wikipedia.org/wiki/HTTP_response_splitting for more information. FindBugs looks only for the most blatant, obvious cases of HTTP response splitting. If FindBugs found any, you almost certainly have more vulnerabilities that FindBugs doesn't report. If you are concerned about HTTP response splitting, you should seriously consider using a commercial static analysis or pen-testing tool.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security - HTTP Response splitting vulnerability
This code directly writes an HTTP parameter to an HTTP header, which allows for a HTTP response splitting vulnerability. See http://en.wikipedia.org/wiki/HTTP_response_splitting for more information. FindBugs looks only for the most blatant, obvious cases of HTTP response splitting. If FindBugs found any, you almost certainly have more vulnerabilities that FindBugs doesn't report. If you are concerned about HTTP response splitting, you should seriously consider using a commercial static analysis or pen-testing tool.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security - JSP reflected cross site scripting vulnerability
This code directly writes an HTTP parameter to JSP output, which allows for a cross site scripting vulnerability. See http://en.wikipedia.org/wiki/Cross-site_scripting for more information. FindBugs looks only for the most blatant, obvious cases of cross site scripting. If FindBugs found any, you almost certainly have more cross site scripting vulnerabilities that FindBugs doesn't report. If you are concerned about cross site scripting, you should seriously consider using a commercial static analysis or pen-testing tool.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security - Nonconstant string passed to execute method on an SQL statement
The method invokes the execute method on an SQL statement with a String that seems to be dynamically generated. Consider using a prepared statement instead. It is more efficient and less vulnerable to SQL injection attacks.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security - Servlet reflected cross site scripting vulnerability
This code directly writes an HTTP parameter to a Server error page (using HttpServletResponse.sendError). Echoing this untrusted input allows for a reflected cross site scripting vulnerability. See http://en.wikipedia.org/wiki/Cross-site_scripting for more information. FindBugs looks only for the most blatant, obvious cases of cross site scripting. If FindBugs found any, you almost certainly have more cross site scripting vulnerabilities that FindBugs doesn't report. If you are concerned about cross site scripting, you should seriously consider using a commercial static analysis or pen-testing tool.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Security - Servlet reflected cross site scripting vulnerability
This code directly writes an HTTP parameter to Servlet output, which allows for a reflected cross site scripting vulnerability. See http://en.wikipedia.org/wiki/Cross-site_scripting for more information. FindBugs looks only for the most blatant, obvious cases of cross site scripting. If FindBugs found any, you almost certainly have more cross site scripting vulnerabilities that FindBugs doesn't report. If you are concerned about cross site scripting, you should seriously consider using a commercial static analysis or pen-testing tool.
|
Findbugs | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Signature Declare Throws Exception
It is unclear which exceptions that can be thrown from the methods. It might be difficult to document and understand the vague interfaces. Use either a class derived from RuntimeException or a checked exception.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Simplify Boolean Expression
Checks for overly complicated boolean expressions.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Simplify Boolean Return
Checks for overly complicated boolean return statements.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Simplify Conditional
No need to check for null before an instanceof; the instanceof keyword returns false when given a null argument.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Singular Field
A field that's only used by one method could perhaps be replaced by a local variable.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Static Variable Name
Checks that static, non-final fields conform to the specified format
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
String Buffer Instantiation With Char
StringBuffer sb = new StringBuffer('c'); The char will be converted into int to intialize StringBuffer size.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
String Instantiation
Avoid instantiating String objects; this is usually unnecessary.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
String Literal Equality
Checks that string literals are not used with == or !=.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
String To String
Avoid calling toString() on String objects; this is unnecessary.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
System Println
System.(out|err).print is used, consider using a logger.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unconditional If Statement
Do not use if statements that are always true or always false.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unnecessary Case Change
Using equalsIgnoreCase() is faster than using toUpperCase/toLowerCase().equals()
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unnecessary Local Before Return
Avoid unnecessarily creating local variables
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unused formal parameter
Avoid passing parameters to methods or constructors and then not using those parameters.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unused Imports
Checks for unused import statements.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unused local variable
Detects when a local variable is declared and/or assigned, but not used.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unused Null Check In Equals
After checking an object reference for null, you should invoke equals() on that object rather than passing it to another object's equals() method.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unused Private Field
Detects when a private field is declared and/or assigned a value, but not used.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Unused private method
Unused Private Method detects when a private method is declared but is unused. This PMD rule should be switched off and replaced by its equivalent from Squid that is more effective : it generates less false-positives and detects more dead code.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Use Array List Instead Of Vector
ArrayList is a much better Collection implementation than Vector.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Use Arrays As List
The class java.util.Arrays has a asList method that should be use when you want to create a new List from an array of objects. It is faster than executing a loop to cpy all the elements of the array one by one
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Use Correct Exception Logging
To make sure the full stacktrace is printed out, use the logging statement with 2 arguments: a String and a Throwable.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Use Index Of Char
Use String.indexOf(char) when checking for the index of a single character; it executes faster.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Use String Buffer Length
Use StringBuffer.length() to determine StringBuffer length rather than using StringBuffer.toString().equals() or StringBuffer.toString().length() ==.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Useless Operation On Immutable
An operation on an Immutable object (BigDecimal or BigInteger) won't change the object itself. The result of the operation is a new object. Therefore, ignoring the operation result is an error.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Useless Overriding Method
The overriding method merely calls the same method defined in a superclass
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Useless String Value Of
No need to call String.valueOf to append to a string; just use the valueOf() argument directly.
|
Pmd | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Visibility Modifier
Checks visibility of class members. Only static final members may be public; other class members must be private unless property protectedAllowed or packageAllowed is set.
|
Checkstyle | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
While Loops Must Use Braces
Avoid using 'while' statements without using curly braces.
|
Pmd |