Inspection Gadgets: unnecessary return

I've got code which looks something like this:

void method()
if (condition1)
// do something

// do something else

The "unnecessary return" inspection picks up the return statement as unnecessary.

While I recognise that, strictly speaking, it is unnecessary, I put it there as clearer documentation that I'll return from the method here.
I want to leave it there in case I decide to add some more code to the method after the "if" statement.

So, would it be possible to separate out "return" statements which occur as the last statement in the main "block" of the method, from those that occur within the blocks within the method?



Submit a JIRA request for such an option, but unless it gets much positive comment I can't say I'm all that thrilled about the idea. The thing about "Unnecessary return" and "Unnecessary continue" is that they get most of their value from reporting places where you thought the return or continue was necessary, but it actually wasn't. If I implemented the semantics you describe, then you're losing the capacity to see places where your control flow was simpler than you actually expected.

Also, IG is feature-frozen until Irida, so if you submit request will be immediately backlogged until then. Sorry for any inconvenience this may cause.

--Dave Griffith


You can suppress specific inspections on a case by case basis. Try it
(Alt-Enter, select the appropriate suppress action).

Rob Harwood
Software Developer
JetBrains Inc.
"Develop with pleasure!"


Please sign in to leave a comment.