Bug 301405 - Warning "Comparing identical expressions" does not take into account that Float.NaN != Float.NaN is true. Same for Double.NaN.
Summary: Warning "Comparing identical expressions" does not take into account that Flo...
Status: CLOSED DUPLICATE of bug 281776
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.6 M1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-01 06:12 EST by Amos Wittenberg CLA
Modified: 2010-03-08 06:22 EST (History)
3 users (show)

See Also:
srikanth_sankaran: review? (Olivier_Thomann)


Attachments
Patch under consideration (2.57 KB, patch)
2010-02-09 08:09 EST, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Amos Wittenberg CLA 2010-02-01 06:12:53 EST
Build Identifier: M20090917-0800

// this is actually the Float and Double implementation of their static method
// isNaN()
boolean isNaN(final float num){
   return (num != num);
}
// It is unclear what @SuppressWarning can be used on the method to suppress
// this.
// In most cases the warning is correct and testing for a NaN is not
// intended.
// It would be a shame to get rid of this useful warning just because formally
// it is incorrect but a clear SuppressWarning QuickFix would be extremely 
// useful.

Reproducible: Always

Steps to Reproduce:
Trivial.
Comment 1 Srikanth Sankaran CLA 2010-02-01 06:24:53 EST
I would have thought the fix for bug#281776 should have
taken care of this ? Will investigate.
Comment 2 Amos Wittenberg CLA 2010-02-01 06:39:39 EST
(In reply to comment #2)
> ... the fix for bug#281776 ...

Missed that one in my pre-submit search.  Sorry.
My Eclipse is still emitting the warning for both float and double.
Comment 3 Srikanth Sankaran CLA 2010-02-01 07:25:55 EST
Version: 3.6.0
Build id: I20100129-1300

with the binary above, on a clean workspace with a small
project with just the class below:

public class Clazz {
	boolean isNaN(final float num){
		   return (num != num);
		}
	boolean isNaN(final double num){
		   return (num != num);
		}
	boolean isNaN(final int num){
		   return (num != num);
		}
}

I see the warning for the int version and not for the
other two. Could you confirm the build id : Help + About Eclipse

If the problem persists, anything special that you can think
of about your situation that could be contributing to it ?
If you clean and rebuild, do you still get it ? Do you get
it on a small test case etc.

If possible try with the above version too (3.6M5)
Comment 4 Srikanth Sankaran CLA 2010-02-09 00:54:05 EST
Hello Amos,

I am able to get the warnings with this test case:

public class Clazz {
	boolean isNaN(Float num) {   // change to float - warning goes away
		return (num != num);
	}

	boolean isNaN(final Double num) { // change to double - warning goes away
		return (num != num);
	}
}

Is this what you could be seeing ? i.e for the primitive types
(float, double) the fix for bug#281776 addressed the problem
while for the boxed types (Float, Double) the issue is still
there ?
Comment 5 Srikanth Sankaran CLA 2010-02-09 08:09:45 EST
Created attachment 158586 [details]
Patch under consideration
Comment 6 Srikanth Sankaran CLA 2010-02-09 08:12:35 EST
Olivier, by code inspection I concluded that this is the
only scenario under which we would issue the warning for
the NaN checking idiom. 

Let me know if you catch some cases that I have overlooked.
Comment 7 Olivier Thomann CLA 2010-02-10 21:07:07 EST
(In reply to comment #4)
> Is this what you could be seeing ? i.e for the primitive types
> (float, double) the fix for bug#281776 addressed the problem
> while for the boxed types (Float, Double) the issue is still
> there ?
Boxed types are objects. So I think the warning in this case is legitimate.
There is no unboxing done when comparing two boxed types.
Did I miss something ?

(In reply to comment #2)
> Missed that one in my pre-submit search.  Sorry.
> My Eclipse is still emitting the warning for both float and double.
It makes sense that it does since you are not using a version >= 3.6M1.

This fix has not been backported to 3.5.1.

I would close as a dup of bug 281776.
Comment 8 Srikanth Sankaran CLA 2010-02-11 00:25:16 EST
(In reply to comment #7)
> (In reply to comment #4)
> > Is this what you could be seeing ? i.e for the primitive types
> > (float, double) the fix for bug#281776 addressed the problem
> > while for the boxed types (Float, Double) the issue is still
> > there ?
> Boxed types are objects. So I think the warning in this case is legitimate.
> There is no unboxing done when comparing two boxed types.
> Did I miss something ?

Oops. No, You are right of course. The warning is legit and
the "fix" is so not.

> (In reply to comment #2)
> > Missed that one in my pre-submit search.  Sorry.
> > My Eclipse is still emitting the warning for both float and double.
> It makes sense that it does since you are not using a version >= 3.6M1.
> 
> This fix has not been backported to 3.5.1.

I went by the date of the build id being later than
the date of 3.6M1 and the Version field of the bug
being (erroneously) set to 3.6. (I realize now that
that the M prefix indicates a maintenance build on
3.5.x stream and not a milestone build on 3.6.x as
I imagined)

Sorry this wasted everyone's time.

*** This bug has been marked as a duplicate of bug 281776 ***
Comment 9 Jay Arthanareeswaran CLA 2010-03-08 06:22:22 EST
Verified for 3.6M6 using build I20100305-1011.