>
>
>
V6121. Return value is not always used.…


V6121. Return value is not always used. Consider inspecting the 'foo' method.

The analyzer has detected a possible error: the method return value is not used, although it is used in most other cases.

Look at the synthetic example:

class Item {
  int getID() {
    ....
  }
}
class ItemController {
  int setNewItem(Item lastItem) {
    Item newItem = new Item(lastItem.getID()); 
    ....
    newItem.getID();                            // <= 
    return newItem.getID(); 
  }
}

In this example, the return value of the 'getID' method is used consistently, except for one case. If the result is not used in less 10% of the total calls, the analyzer generates a warning.

In some cases, the return value doesn't have to be used. For example, if a method has side effects (changing properties, fields, writing/reading a file, and so on), the return value can be ignored.

To mark that the behavior is intended, leave a comment next to the call where the result is ignored:

int updateItem() {
  ....
  return 0; 
}
....
void someMethod() {
  ....
  updateItem(); // ignore result
}