Unnecessary call to 'toString()'
Reports calls to toString()
that are used in the following cases:
In string concatenations
In the
java.lang.StringBuilder#append()
orjava.lang.StringBuffer#append()
methodsIn the methods of
java.io.PrintWriter
orjava.io.PrintStream
in the methods
org.slf4j.Logger
In these cases, conversion to string will be handled by the underlying library methods, and the explicit call to toString()
is not needed.
Example:
After the quick-fix is applied:
Note that without the toString()
call, the code semantics might be different: if the expression is null, then the null
string will be used instead of throwing a NullPointerException
.
Use the Report only when qualifier is known to be not-null option to avoid warnings for the values that could potentially be null.
Inspection options
Option | Type | Default |
---|---|---|
Report only when qualifier is known to be not-null | Checkbox | true |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |