This is a further improvement of my side effect methods analysis. This analysis can help to detect void non-empty methods which execution will have no visible effect. I think I found very good false-positive/false-negative balance, so false-positives rate will be quite low.
First tests show that usually this warns about partially outcommented methods like this:
void myMethod() { if(someCondition) { /* outcommented code blob is here */ } }
In such cases it's better to outcomment the condition as well as empty method have much more chances to be inlined.
Also it uncovers really cool bugs. For example, this SortedSet#merge method which has 26 lines, but actually does nothing. Another example is VirtualManager#removeIndicesFromTo:
public void removeIndicesFromTo(int from, int to) { int indexAfterTo = to + 1; Object[] newCache = new Object[cachedElements.length - (indexAfterTo - from)]; System.arraycopy(cachedElements, 0, newCache, 0, from); if (indexAfterTo < cachedElements.length) { System.arraycopy(cachedElements, indexAfterTo, newCache, from, cachedElements.length - indexAfterTo); } }
It was forgotten to write cachedElements = newCache at the end of this method.
Will commit after final polishing and testing.
The code is committed:
https://code.google.com/p/findbugs/source/detail?r=92591277209d995ef6154e0d7d6adeccfb706269
One more interesting case found by this pattern: CheatSheetRegistryReader#pruneEmptyCategories
Here recursive tree traversal is performed without any side-effect.
Some improvements for RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT were also implemented to reduce false-positives.
False-negatives were discovered when method contains any synchronized or finally block (even if it's actually useless). Fixed:
https://code.google.com/p/findbugs/source/detail?r=4f8634b040f8ceba34616a31686a246bc2dc7e3a