idea for inspection

hi there,

idea should have an inspection that checks for unused return values of methods which are guaranteed to not change a state. for example, if there is a method like this:
public String createSomethingAndDoNotChangeAnyState() { return "hello inspection"; }

calling it without using the return value (and by "not using" i include "not declaring one"  is a bug. it *must* be one since the whole purpose of calling such a method is to do something with the result.
i know it's not always possible to figure out if a method has side effects (for example if the source code is not available or if it's an abstract or interface call), but in many cases it is.

what do you think?

Comment actions Permalink

There is already an inspection for unused return values though it covers all unused return values and not just the specific case you mention.  It's under the Declaration Redundancy group in the inspections.

You may already know this and are looking for an "enhanced" version but just FYI in case you weren't aware.

Comment actions Permalink

i checked before creating the thread. the inspection reports unused declared variables. what i am proposing is an inspection which doesn't reports unused declarations, but method calls themselves which are guaranteed to have no effect.

Comment actions Permalink

Actually I made a mistake and the inspection I was thinking of is under Probable Bugs: Result of method call ignored.

While again it doesn't check so see if the state changed it will report that there is a return value that you're not doing anything with (which I think is what you want?).  If you declare a variable for the return value but don't do anything with it that's a different inspection.

The warning I have selected below shows the unused return value while the greyed out "deleted" variable shows the unused variable message.



Please sign in to leave a comment.