Community
Participate
Working Groups
Build ID: 20090621-0832 Steps To Reproduce: 1. In a class, declare variable var of type float or double. 2. Write "if(var != var) ..." 3. You get a warning for comparing identical expressions, while this comparison is idiom for checking for NaN. There should be an option for turning off identical expression comparison for double and float expression types. More information: public class IdenticalExpressionWarningOnDoubles { public static void main(String[] args) { double var = Double.NaN; if(var != var) { System.out.println("NaN"); } } }
And why don't you use this code pattern (java.lang.Double.isNaN(double))? public class IdenticalExpressionWarningOnDoubles { public static void main(String[] args) { double var = Double.NaN; if(Double.isNaN(var)) { System.out.println("NaN"); } } }
I do not want to refactor the legacy code which does contains such expressions. At least not until Eclipse provides quick fix for this :) Yes, I can use SuppressWarning too, but it looks cumbersome, and is sort of refactoring too.
(In reply to comment #2) > I do not want to refactor the legacy code which does contains such expressions. > At least not until Eclipse provides quick fix for this :) Yes, I can use > SuppressWarning too, but it looks cumbersome, and is sort of refactoring too. It sounds reasonable to unconditionally tolerate these cases as a legitimate idiom for testing for NaNs. Olivier, what do you think ? Or do you see enough justification for introducing an option that the user can set/unset ?
Created attachment 141735 [details] Patch possibility
re comment 3: I agree. We shouldn't issue invalid warnings and adding an option to do some seems wrong.
I don't think we need to add a new option for this. Comparison between two identical float or double expression cannot be reported as a warning because of the common pattern to check NaN. Srikanth, please go forward and release the patch. No need to backport to 3.5.1 as this is not a severe problem.
Fix and tests released in HEAD for 3.6M1
Verified for 3.6M1 using build 20090802-2000.
*** Bug 301405 has been marked as a duplicate of this bug. ***
*** Bug 251227 has been marked as a duplicate of this bug. ***
*** Bug 309087 has been marked as a duplicate of this bug. ***