Community
Participate
Working Groups
3.2M3 There's a warning for assignments from same to same (like x = x) But there's none for comparisons of that kind. Those are just as likely to be bogus. Example class Foo{ final int x; Foo(int x){ this.x= x;} @Override public int hashCode() { return x * 997; } @Override public boolean equals(Object obj) { if (obj instanceof Foo){ Foo foo = (Foo) obj; return x == x; //<<< BUG that could be flagged early } else return false; } }
Philippe, Should we investigate such a warning?
Created attachment 103604 [details] Proposed patch combined with patch for bug 235004
Fixed, released for 3.5M1
Added ProgrammingProblemsTest#test037
Added a new compiler warning to detect comparisons between identical expressions. This diagnosis is controlled by option: JavaCore.COMPILER_PB_COMPARING_IDENTICAL and produces a problem marker which ID is IProblem.ComparingIdentical problem ID. Compiler option ID: Reporting Comparison of Identical Expressions. When enabled, the compiler will issue an error or a warning if a comparison is involving identical operands (e.g 'x == x'). - Option id:"org.eclipse.jdt.core.compiler.problem.comparingIdentical" - Possible values: { "error", "warning", "ignore" } - Default: "warning"
entered bug 238226 for ui counterpart
Verified for 3.5M1 using I20080805-1307