Java

Java

Made by DeepSource
Class overrides TestCase but has no test methods JAVA-S0341
Anti-pattern
Minor

This class is a JUnit TestCase but has not implemented any test methods. Did you forget to implement them?

Object appears to have been created for no reason JAVA-S0235
Anti-pattern
Minor

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.

Class is not an Exception/Throwable, even though it is named as such JAVA-S0182
Anti-pattern
Minor

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.

Iterator next method must throw NoSuchElementException JAVA-S0146
Anti-pattern
Major

This 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.

IllegalMonitorStateExceptions should not be handled JAVA-S0040
Anti-pattern
Critical

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).

Possible database resource leak detected JAVA-S0327
Anti-pattern
Critical

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-S0056
Anti-pattern
Major

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.

Private method is never called JAVA-S0324
Anti-pattern
Minor

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-W0077
Anti-pattern
Minor
Autofix

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 static .class property of the class itself.

synchronized block is empty JAVA-W0151
Anti-pattern
Major

The code contains an empty synchronized block. This could confuse readers of this code later.

Stream does not appear to be closed after use JAVA-S0268
Anti-pattern
Critical

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.

Method may ignore exceptions JAVA-S0052
Anti-pattern
Major

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 JAVA-S0412
Anti-pattern
Minor

Method uses the same code for two switch clauses This method uses the same code to implement two clauses of a switch statement.

Stream may be left unclosed JAVA-S0269
Anti-pattern
Critical

The method creates an IO stream object but does not appear to do any of the following: * Assign the stream to any fields

Imprecise redefinition of library constant JAVA-W1033
Anti-pattern
Major

A library constant has been redefined in source code with a different/imprecise value.

Useless control flow detected JAVA-W1047
Anti-pattern
Minor

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:

Empty catch clauses may hide exceptions JAVA-E0052
Anti-pattern
Major

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.

Protected fields in a final class are useless JAVA-W0417
Anti-pattern
Minor
Autofix

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.

Synchronization performed on a util.concurrent Lock object JAVA-S0321
Anti-pattern
Critical

This 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.

Random instances should be reused JAVA-W1015
Anti-pattern
Major

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.