Java

Java

By DeepSource

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.

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.

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.

Methods should not have different nullability than their super methods JAVA-E1100
Bug risk

If a method of a superclass has one particular nullability annotation applied to it, avoid marking any overrides in subtypes with a different nullability annotation.

Make sure to use the same annotation present on the super method as much as possible.

JUnit test class overrides setUp but does not invoke super.setUp() JAVA-S0337
Bug risk

This class inherits from JUnit's TestCase class and implements the setUp() method. The setUp method should call super.setUp(), but doesn't.

@OverridingMethodsMustInvokeSuper annotation in super method is ignored by overriding method JAVA-S0001
Bug risk

The super method is annotated with @OverridingMethodsMustInvokeSuper, but the overriding method isn't calling the super method.

A call has been made to an unsupported method JAVA-S0013
Bug risk

A call has been made to an unsupported method.

Attempt to close a null value detected JAVA-S0250
Bug risk

close() is being invoked on a value that is always null. If this statement is executed, a null pointer exception will occur. Another serious issue is the fact that the resource that is meant to be closed is not closed.

Loops must terminate by some means JAVA-S0024
Bug risk

This loop doesn't seem to have a way to terminate (other than by perhaps throwing an exception).

It is better to explicitly break out of the loop instead of relying on a possibly unclear exit condition.

BigDecimal constructed from double may be imprecise JAVA-S0008
Bug risk

BigDecimals constructed from a double may not be represented correctly.

Class extends Servlet class and uses instance variables JAVA-S0370
Bug risk

This class extends from a Servlet class, and uses an instance member variable. Since only one instance of a Servlet class is created by the J2EE framework, and it is used in a multithreaded way, this paradigm is highly discouraged and most likely problematic. Consider only using method local variables, or implement proper synchronization on the static fields.

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.

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.

Avoid using deprecated Thread methods JAVA-E1107
Bug risk

Deprecated methods from java.lang.Thread such as Thread.stop() or Thread.suspend() should not be used as they can cause instability.

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.

Boolean method may return null JAVA-S0030
Bug risk

A method with a Boolean return type returns an explicit null. This is likely intentional, but be aware that API consumers may not realize that.

Impossible downcast of toArray() result detected JAVA-S0386
Bug risk

This code is casting the result of calling toArray() on a collection to a subtype of Object[], as in:

Avoid throwing null JAVA-E1097
Bug risk
Autofix

Throwing null is a bad practice and should be avoided, as it serves no meaningful purpose.