When the call to a function doesn't have any side effects, what is the point of making the call if the results are ignored? In such case, either the function call is useless and should be dropped or the source code doesn't behave as expected.
To prevent generating any false-positives, this rule triggers an issues only on the following predefined list of immutable classes in the Java API
: String
, Boolean
, Integer
, Double
, Float
, Byte
, Character
,
Short
, StackTraceElement
.
public void handle(String command){ command.toLowerCase(); // Noncompliant; result of method thrown away ... }
public void handle(String command){ String formattedCommand = command.toLowerCase(); ... }