Java

Java

Made by DeepSource
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.

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.

Inefficient use of keySet iterator instead of entrySet iterator JAVA-S0361
Performance
Major

This method accesses the value of a Map entry, using a key that was retrieved from a keySet iterator. It is more efficient to use an iterator on the entrySet of the map, to avoid the Map.get(key) lookup.

Prepared statements should not be created within a loop JAVA-S0329
Performance
Critical

The method calls Connection.prepareStatement inside the loop passing the constant arguments. If the PreparedStatement should be executed several times there's no reason to recreate it for each loop iteration.

toString invoked on a string value is useless JAVA-S0064
Performance
Major

Calling String.toString is a redundant operation. Just use the string directly.

Boolean constructor is inefficient, consider using Boolean.valueOf instead JAVA-S0066
Performance
Major

Creating new instances of java.lang.Boolean wastes memory, since Boolean objects are immutable and there are only two useful values of this type.

Integer/Long constructor is inefficient, use valueOf instead JAVA-S0067
Performance
Major

Using Integer's default constructor is guaranteed to always result in a new object whereas Integer.valueOf allows the compiler/class library/JVM to cache values, which is known as interning.

Float/Double constructor is inefficient, use valueOf instead JAVA-S0068
Performance
Major

Using Float or Double's default constructor is guaranteed to always result in a new object whereas the valueOf method of these classes allows the JVM to cache values, which is known as interning.

Use "" instead of new String() to create empty strings JAVA-S0063
Performance
Major

Creating a new java.lang.String object using the default constructor wastes memory because the object so created will be functionally indistinguishable from the empty string constant "".

Inefficient use of String constructor JAVA-S0062
Performance
Major

Creating a String using object creation wastes memory because the new String object so constructed will be functionally indistinguishable from the String value passed as a parameter. Just use the string directly.

Explicit invocation of garbage collection is detrimental apart from some benchmarking use cases JAVA-S0065
Performance
Major

This code explicitly invokes garbage collection via System.gc or Runtime.gc. Except for specific use in benchmarking, this is very dubious.

Maps and Sets of URLs can be performance hogs JAVA-P0057
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.

Inefficient use of String constructor JAVA-P0062
Performance
Major

Creating a String using object creation wastes memory because the new String object so constructed will be functionally indistinguishable from the String value passed as a parameter. Just use the string directly.

Use "" instead of new String() to create empty strings JAVA-P0063
Performance
Major

Creating a new java.lang.String object using the default constructor wastes memory because the object so created will be functionally indistinguishable from the empty string constant "".

toString invoked on a string value is useless JAVA-P0064
Performance
Major

Calling String.toString is a redundant operation. Just use the string directly.

Explicit invocation of garbage collection is detrimental apart from some benchmarking use cases JAVA-P0065
Performance
Major

This code explicitly invokes garbage collection via System.gc() or Runtime.gc(). Except for specific use in benchmarking, this is very dubious.

Boolean constructor is inefficient, consider using Boolean.valueOf instead JAVA-P0066
Performance
Major

Creating new instances of java.lang.Boolean wastes memory, since Boolean objects are immutable and there are only two useful values of this type.

Integer/Long constructor is inefficient, use valueOf instead JAVA-P0067
Performance
Major

Using Integer's default constructor is guaranteed to always result in a new object whereas Integer.valueOf allows the compiler/class library/JVM to cache values, which is known as interning.

Float/Double constructor is inefficient, use valueOf instead JAVA-P0068
Performance
Major

Using Float or Double's default constructor is guaranteed to always result in a new object whereas the valueOf method of these classes allows the JVM to cache values, which is known as interning.

Pattern.compile() should not be called in a loop JAVA-P0331
Performance
Critical

This method calls Pattern.compile() inside a loop with constant arguments. If this Pattern will be used several times, there's no reason to compile it on each loop iteration.