Java

Java

Made by DeepSource
Duration.withNanos() may not produce correct results JAVA-E1087
Bug risk
Major

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
Major

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
Major

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
Major

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
Major

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
Major

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
Major

A call has been made to an unsupported method.

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

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
Critical

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
Major

BigDecimals constructed from a double may not be represented correctly.

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

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.

Boolean method may return null JAVA-S0030
Bug risk
Major

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
Critical

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

Overwriting a method parameter will not modify the original object JAVA-S0352
Bug risk
Critical

This method ignores the original value of a parameter and attempts to assign a new value to it. This often indicates a mistaken belief that the write to the parameter will be conveyed back to the caller. Because a parameter is just a copy of a reference from the calling scope, overwriting it will only modify the method's local copy of the reference, not the calling scope's copy.

Method with Optional return type must not return null JAVA-S0031
Bug risk
Critical

The usage of an Optional return type (java.util.Optional or com.google.common.base.Optional for Java 7) always means that explicit null returns were not desired by design.

System.exit() should only be invoked within application entry points JAVA-S0060
Bug risk
Major

This method invokes System.exit(), and is called by other code. This can prevent proper error handling and debugging.

Possible null access JAVA-E1083
Bug risk
Critical

This code contains a possible null pointer dereference. Double-check the code to ensure that the concerned variable always has a non-null value when accessed.

Possible null access due to exception handling JAVA-E1084
Bug risk
Critical

This code contains a possible null dereference that may occur based on whether an exception is thrown or not. Carefully check your code to ensure that the concerned value can never be null at this point.

Iterators should not be invalidated while in scope JAVA-E1085
Bug risk
Major

Collections should not be modified when an iterator is still in scope.

equals method does not handle null valued operands JAVA-S0110
Bug risk
Critical

This implementation of equals violates the contract defined by java.lang.Object.equals because it does not check for null being passed as the argument.