Bug 128547 - [compiler][null] null reference analysis: false positive in try/finally
Summary: [compiler][null] null reference analysis: false positive in try/finally
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-19 11:26 EST by Görge Albrecht CLA
Modified: 2006-04-03 11:57 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Görge Albrecht CLA 2006-02-19 11:26:29 EST
In the following code the "null reference analysis" produces a false positive:
1:		Object o = null;
2:		try {
3:			o = createObject();
4:			System.out.println(o.toString());
5:			return o;
6:		} finally {
7:			if (o != null) {
8:				System.out.println(o.toString());
9:			}
10:		}
If createObject() in line 3 returns null, "o.toString()" in line 4 raises a NullPointerException. Further on the finally block is executed with "o" being null. Without "interprocedural analysis" the "taint" should be removed from "o".

Besides from this bug, it's a great feature. Thanks!
Comment 1 Maxime Daniel CLA 2006-03-15 10:13:46 EST
Added class NullInfoRegistry to track potential changes made within the try blocks. Added test cases NullReferenceTest # 513 to 516 to illustrate the new
behavior.

(The trick is the following: since a try block may be exited at any point, any operation upon a reference within it mitigates whatever we know for sure, except if all operations are congruent - aka, null, null, null or non null, non null...
This unique behavior motivates the introduction and use of NullInfoRegistry. Note that this class does not represent the null information at a precise point in the flow, but collects all null related operations effects for a given context.)
Comment 2 Frederic Fusier CLA 2006-03-28 05:46:03 EST
Verified for 3.2 M6 using warm-up build I20060327-0010.
Comment 3 Görge Albrecht CLA 2006-04-03 11:57:43 EDT
Verified in 3.2M6. Mark as closed. Thanks.