Bug 310074 - Warning for unnecessary boolean operations
Summary: Warning for unnecessary boolean operations
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-22 05:24 EDT by Markus Keller CLA
Modified: 2010-04-22 05:24 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2010-04-22 05:24:54 EDT
N20100421-2000

Would be nice to have a warning for unnecessary boolean operations that should be simplified.

Example (there are probably more cases):

public class Try {
    boolean foo(boolean b) {
        b&= true; // b unchanged
        b&= false; // b= false
        b|= false; // b unchanged
        b= b & true; // b unchanged
        if (b) { // 'if(b)' followed by 'return true' and 'return false'
                 // should be written as: 'return b' (with a '!' if reversed)
            return true;
        }
        return false;
    }
    
    boolean bar() {
        return Math.random() < .5 ? false : true;
        // use 'return !(Math.random() < .5)' 
    }
}


This would e.g. help to spot wrong implementations like ApiFilterStore#removeFilters(IApiProblemFilter[]), which uses
"success &= true;" and "success &= false;" in a for-loop (that case does not cause problems in the current code base, because the return value is only used in an invocation that passes a single filter).