TestCase
but has no test methods JAVA-S0341This class is a JUnit TestCase but has not implemented any test methods. Did you forget to implement them?
Our analysis shows that this object is useless. It's created and modified, but its value never goes outside the method or produces any side effect. Either there is a mistake and the object was intended to be used or it can be removed.
This class is not an exception, and does not extend Throwable
or any other exception class, but ends with 'Exception'
. This may be confusing to users of this class.
next
method must throw NoSuchElementException
JAVA-S0146This class implements the java.util.Iterator
interface. However, its next()
method is not capable of throwing java.util.NoSuchElementException
. This is a violation of the Iterator
interface's contract, and will not work with code that expects next()
to throw when the iterator is exhausted.
IllegalMonitorStateException
s should not be handled JAVA-S0040IllegalMonitorStateException
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).
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.
Thread
passed where Runnable
expected JAVA-S0056A 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.
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. Unless this method is intended to be used with reflection, it is recommended to remove it to increase code clarity.
Object.getClass
does not need to be invoked on an instantiated object JAVA-W0077This 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 static .class
property of the class itself.
synchronized
block is empty JAVA-W0151The code contains an empty synchronized block. This could confuse readers of this code later.
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. While the stream could possibly be closed when it is garbage collected, it is not guaranteed, and relying on the garbage collector to dispose of used resources is an exceptionally bad habit.
This method might ignore an exception. In general, exceptions should be handled, reported in some way, or rethrown by the method.
Method uses the same code for two switch clauses This method uses the same code to implement two clauses of a switch statement.
The method creates an IO stream object but does not appear to do any of the following: * Assign the stream to any fields
A library constant has been redefined in source code with a different/imprecise value.
This method contains a useless control flow statement, where control flow continues onto the same place regardless of whether the branch is taken or not. For example, this is caused by having an empty statement block for an if
statement, or having a conditional that always fails or succeeds:
When a catch
clause is empty, it essentially ignores any occurrences of the particular exception it handles. This could allow critical bugs to go undiagnosed because any relevant exceptions indicative of a bug would be discarded within this catch
block.
This class is declared to be final, but declares fields to be protected. Such code is confusing, since protected fields in final classes are effectively the same as private fields.
Lock
object JAVA-S0321This method performs synchronization on an object that implements java.util.concurrent.locks.Lock
. Such an object is locked/unlocked using acquire()
/release()
rather than using the synchronized (...)
construct.
Creating a new instance of java.util.Random
every time a random value is required is wasteful. In addition, the randomness of the values produced is reduced due to increased predictability of the random number generation.
Store a single Random
instance and reuse it for best effect.