Java

Java

By DeepSource

ZoneId.of("Z") should be replaced with ZoneOffset.UTC JAVA-W1085
Anti-pattern
Autofix

Avoid calling ZoneId.of() to get the UTC timezone offset, and instead use ZoneOffset.UTC directly.

Static methods should be accessed using the class instance JAVA-W1029
Anti-pattern
Autofix

While it is possible to access static members of a class through an instance of that class, it is a bad practice to do so.

Always access a static member through the declaring class itself, not an instance of the class.

Object.getClass does not need to be invoked on an instantiated object JAVA-W0077
Anti-pattern
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.

Method superfluously delegates to parent class method JAVA-W1016
Anti-pattern
Autofix

This method appears to only call its superclass implementation, while directly passing its parameters to the super method. This method can be removed, as it provides no additional value.

equals() method parameters should not be marked with @NotNull or equivalent annotations JAVA-W1028
Anti-pattern
Autofix

Implementations of the equals() method should not indicate to API consumers that they expect their argument to be non-null.

API consumers should leave null checking to the equals() implementation.

Thread.currentThread() should not be used to call Thread's static methods JAVA-W1038
Anti-pattern
Autofix

This method invokes Thread.currentThread() just to call one of Thread's static methods.

Most static methods of Thread operate on the current thread, so there is no need to explicitly get the current thread object to call them.

Method can be declared static JAVA-W1057
Anti-pattern
Autofix

Private final methods that do not access instance fields should be declared static.

switch statements with only 2 branches should be if statements instead JAVA-W1086
Anti-pattern
Autofix

switch statements that have only two arms can be better represented as if statements.

Inject annotations on abstract class constructors have no effect JAVA-W1084
Anti-pattern
Autofix

The constructor of an abstract class can never be called directly by the dependency injection framework, meaning any injection annotations applied to it will not be considered. Remove the annotation.

Returned Futures should not be ignored JAVA-W1087
Anti-pattern

Always use the value returned by a method with return type Future<T>.

For loop can be converted into a foreach loop JAVA-W1089
Anti-pattern

If a for loop can be converted to a foreach loop, consider doing so, as it is a more concise and readable syntax.

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

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.

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

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.

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

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.

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

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

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.

Empty zip file entries should not be created JAVA-S0038
Anti-pattern

The code calls putNextEntry(), immediately followed by a call to closeEntry(). This results in an empty ZipFile entry.

IllegalMonitorStateExceptions should not be handled JAVA-S0040
Anti-pattern

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

@Inject detected on a final field JAVA-W1071
Anti-pattern
Autofix

@javax.inject.Inject should not be used on final fields.