Java

Java

By DeepSource

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.

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.

Primitives do not need to be boxed for comparison JAVA-W1050
Performance
Autofix

A boxed primitive is created just to call its compareTo method. It's more efficient to use the associated static compare method (for double and float since Java 1.4, for other primitive types since Java 7) which works on primitives directly.

Malformed JavaDoc comment JAVA-D1007
Documentation

This JavaDoc comment appears to be malformed. Such comments may raise errors or cause crashes when passed to a JavaDoc generation tool.

Rewrite the comment to use correct syntax.

Duration.withNanos() may not produce correct results JAVA-E1087
Bug risk

Using Duration.withNanos() may produce wrong results, because it will only set the value of the nanoseconds field of the duration, and will not correctly adjust for any overflow.

Parameter tag has no description JAVA-D1005
Documentation

This method/constructor has a parameter tag with no description.

Consider adding a description to the tag. If the parameter's name is clear enough, consider removing the parameter tag entirely.

JavaDoc tags should not be empty JAVA-D1006
Documentation

Empty JavaDoc tags are meaningless, and may even cause tools that consume JavaDoc comments to crash.

Always add an explanation when writing JavaDoc tags.

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.

ZoneId.of() should be passed a valid timezone identifier JAVA-E1092
Bug risk

java.time.ZoneId.of() should not be passed invalid time zone identifier strings, as this will cause exceptions to be thrown at runtime.

Double assignment of variable detected JAVA-E1063
Bug risk
Autofix

A double assignment of a variable to itself has been detected. This may be a typo.

Check whether this is correct and edit it or remove the extra assignment.

readResolve must return Object JAVA-E1032
Bug risk
Autofix

readResolve() must return only java.lang.Object, not any other type.

serialVersionUID should be correctly declared JAVA-E1042
Bug risk
Autofix

The serialVersionUID field must be declared as <access modifier> static final long serialVersionUID. Not declaring it as such will prevent Java from processing it.

Calls to assertion chain methods should be terminated with an assertion JAVA-E1109
Bug risk

Always terminate calls to assertThat() or verify() with a relevant assertion call, such as equals(), or similar.

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.

Downcast may flip integer sign in comparator method JAVA-E1102
Bug risk

The Java analyzer has detected a narrowing cast of a subtraction in a comparison method that may flip the sign of the result.

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.