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.

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.

String concatenation using + within loops is costly and should be replaced by a StringBuffer/StringBuilder JAVA-P1006
Performance
Major

The method seems to be building a String using concatenation in a loop. In each iteration, the String is converted to a StringBuffer/StringBuilder, appended to, and converted back to a String.

This can lead to a cost of `O(n^2)`` where n is the number of iterations, as the growing string is recopied in each iteration. This issue is detected only on Java versions 8 and below.

Useless unboxing of a value JAVA-W1052
Performance
Minor

A boxed value is unboxed and then immediately reboxed. This has likely occurred due to an unboxing operation by the programmer, which the java compiler has undone.

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.

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.

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.