Inspectopedia
 
2024.3

Result of method call ignored

Warning
New
Last modified: 03 December 2024

Reports method calls whose result is ignored.

For many methods, ignoring the result is perfectly legitimate, but for some it is almost certainly an error. Examples of methods where ignoring the result is likely an error include java.io.inputStream.read(), which returns the number of bytes actually read, and any method on java.lang.String or java.math.BigInteger. These methods do not produce side-effects and thus pointless if their result is ignored.

The calls to the following methods are inspected:

  • Simple getters (which do nothing except return a field)

  • Methods specified in the settings of this inspection

  • Methods annotated with org.jetbrains.annotations.Contract(pure=true)

  • Methods annotated with .*. CheckReturnValue

  • Methods in a class or package annotated with javax.annotation.CheckReturnValue

  • Optionally, all non-library methods

Calls to methods annotated with Error Prone's or AssertJ's @CanIgnoreReturnValue annotation are not reported.

Use the inspection settings to specify the classes to check. Methods are matched by name or name pattern using Java regular expression syntax. For classes, use fully-qualified names. Each entry applies to both the class and all its inheritors.