Bug 115814 - [compiler] warning on comparing same to same
Summary: [compiler] warning on comparing same to same
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC All
: P3 enhancement (vote)
Target Milestone: 3.5 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 243414
  Show dependency tree
 
Reported: 2005-11-10 09:53 EST by Adam Kiezun CLA
Modified: 2008-08-07 09:53 EDT (History)
0 users

See Also:


Attachments
Proposed patch (50.18 KB, patch)
2008-06-04 13:23 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Kiezun CLA 2005-11-10 09:53:40 EST
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;
	}
}
Comment 1 Olivier Thomann CLA 2006-10-10 13:54:53 EDT
Philippe,

Should we investigate such a warning?
Comment 2 Philipe Mulet CLA 2008-06-04 13:23:18 EDT
Created attachment 103604 [details]
Proposed patch

combined with patch for bug 235004
Comment 3 Philipe Mulet CLA 2008-06-23 11:51:19 EDT
Fixed, released for 3.5M1
Comment 4 Philipe Mulet CLA 2008-06-23 11:54:34 EDT
Added ProgrammingProblemsTest#test037
Comment 5 Philipe Mulet CLA 2008-06-24 07:23:01 EDT
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"
Comment 6 Philipe Mulet CLA 2008-06-24 07:24:13 EDT
entered bug 238226 for ui counterpart
Comment 7 Kent Johnson CLA 2008-08-06 12:58:53 EDT
Verified for 3.5M1 using I20080805-1307