Bug 128014

Summary: [compiler][null] invalid analysis when redundant check is done
Product: [Eclipse Project] JDT Reporter: Joris Verschoor <jbverschoor>
Component: CoreAssignee: Maxime Daniel <maxime_daniel>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: max.gilead
Version: 3.2   
Target Milestone: 3.2 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Fix with test cases none

Description Joris Verschoor CLA 2006-02-15 08:15:57 EST
The folowing code results in an invalid warning:

String s = "";
if (s != null) {
    System.out.println(s);
}
s.toString();


The if check is redundant (there's a warning), but the compiler will complain about s.toString();
Comment 1 Philipe Mulet CLA 2006-02-15 08:48:10 EST
Agreed
Comment 2 Maxime Daniel CLA 2006-02-15 12:43:16 EST
A case of second occurrence diagnostic.

Agree that the given example looks odd.

Still, how would you cope with the following:

String s = "";
if (s != null) {                 // (a)
    System.out.println(s);      
}
else {
    s.toString();                // (b)
}
s.toString();                    // (c)

Current implementation (3.2 M5) complains on a, b and c.
The current bug asks that c stops complaining.
What about b?
Comment 3 Maxime Daniel CLA 2006-02-27 12:10:14 EST
Created attachment 35413 [details]
Fix with test cases

Added NullReferenceTest tests # 333 to 335 (the last is not activated, see fup bug 129581 for details).
The idea of the fix is to merge definite non null with protected null into a non potential null. This does not work for 335 because we only have protected non null in the then branch.
Comment 4 Maxime Daniel CLA 2006-02-27 12:11:26 EST
Fixed and released in HEAD.
Comment 5 Maxime Daniel CLA 2006-03-23 09:07:44 EST
*** Bug 129122 has been marked as a duplicate of this bug. ***
Comment 6 Frederic Fusier CLA 2006-03-28 06:00:31 EST
Verified for 3.2 M6 using warm-up build I20060327-0010.