All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S2201.html Maven / Gradle / Ivy

The newest version!

When the call to a function doesn't have any side effect, what is the point of ignoring the result of the function call ? 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.

Noncompliant Code Example

public void handle(String command){
  command.toLowerCase(); // Noncompliant; result of method thrown away
  ...
}

Compliant Solution

public void handle(String command){
  String formattedCommand = command.toLowerCase();
  ...
}

See

  • MISRA C:2012, 17.7 - The value returned by a function having non-void return type shall be used
  • CERT, EXP12-C - Do not ignore values returned by functions
  • CERT, EXP12-CPP - Do not ignore values returned by functions or methods




© 2015 - 2025 Weber Informatics LLC | Privacy Policy