Bug 128014 - [compiler][null] invalid analysis when redundant check is done
Summary: [compiler][null] invalid analysis when redundant check is done
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 129122 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-02-15 08:15 EST by Joris Verschoor CLA
Modified: 2006-03-28 06:00 EST (History)
1 user (show)

See Also:


Attachments
Fix with test cases (6.86 KB, patch)
2006-02-27 12:10 EST, Maxime Daniel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.