ZoneId.of("Z")
should be replaced with ZoneOffset.UTC
JAVA-W1085Avoid calling ZoneId.of()
to get the UTC timezone offset, and instead use ZoneOffset.UTC
directly.
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.equals()
JAVA-W1080Comparing two primitive values with Objects.equals()
can be inefficient, since both primitives will have to be boxed before being compared.
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.
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-W1028Implementations 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.
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.
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-W1086switch
statements that have only two arms can be better represented as if
statements.
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.
Future
s should not be ignored JAVA-W1087Always use the value returned by a method with return type Future<T>
.
If a for loop can be converted to a foreach loop, consider doing so, as it is a more concise and readable syntax.
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.
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.
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.
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.
The code calls putNextEntry()
, immediately followed by a call to closeEntry()
. This results in an empty ZipFile
entry.
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).
@Inject
detected on a final field JAVA-W1071@javax.inject.Inject
should not be used on final fields.