Java

Java

Made by DeepSource
ZoneId.of("Z") should be replaced with ZoneOffset.UTC JAVA-W1085
Anti-pattern
Major
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
Minor
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
Major

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

Parameter tag has no description JAVA-D1005
Documentation
Major

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
Major

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

Always add an explanation when writing JavaDoc tags.

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.

Inject annotations on abstract class constructors have no effect JAVA-W1084
Anti-pattern
Major
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.

Storing an externally mutable value into a private static field may expose internal state JAVA-S0134
Security
Major

This code stores a reference to an externally mutable object into a static field. If unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. It may be possible for external code to inspect or change the value of the static field by holding a reference to it after passing it to this class.

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.

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

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

Unnecessary imports detected JAVA-W1069
Anti-pattern
Major

Unused imports should be removed from all source files.

Public static method returns freely modifiable array that may expose internal state JAVA-S0131
Security
Major

A public static method returns a reference to an array that is part of the static state of the class. Any code that calls this method can freely modify the underlying array. This is dangerous because it could allow external code to modify the behavior of the class by changing data asssumed to be invariant.

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

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
Major

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.

Maps and Sets of URLs can be performance hogs JAVA-S0057
Performance
Critical

This method or field is or uses a Map or Set of URLs. Since both the equals and hashCode method of URL perform domain name resolution, this can result in a big performance hit.

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