Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try
Summary: [compiler][null] Wrong warning "Redundant null check" in outer catch of neste...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 8
: P3 normal (vote)
Target Milestone: 4.3 M6   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-18 09:53 EST by Dietmar Hechensteiner CLA
Modified: 2013-03-12 02:04 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dietmar Hechensteiner CLA 2013-02-18 09:53:37 EST
// Compile this
import java.util.Date;

public class WrongRedundantNullCheck {

	private static void occasionallyThrowException() throws Exception {
		if ((System.currentTimeMillis() & 1L) != 0L)
			throw new Exception();
	}

	private static Date createDate() throws Exception {
		occasionallyThrowException();
		return new Date();
	}

	public static void main(String s[]) {
		Date d = null;
		try {
			d = createDate();
			System.out.println(d.toString());
			try {
				occasionallyThrowException();
			}
			catch (Exception exc) {
			}
		}
		catch (Exception exc) {
			if (d != null) // Wrong warning in this line
				System.out.println(d.toString());
		}
	}
}
Comment 1 Stephan Herrmann CLA 2013-02-22 17:46:19 EST
Thanks also for this report.

Similar to bug 401088 we have a problem with propagating effects from nested structures to their enclosing.
Here information was propagated as definite, where effects only potentially affected the outer.
Specifically, the information that after "d.toString()" 'd' is known to be non-null was unconditionally propagated into the catch block.
This was wrong because because the catch block could also be entered before reaching that expression.

I have a simple fix currently being tested.
Comment 2 Stephan Herrmann CLA 2013-02-22 18:40:48 EST
Released for 4.3 M6 via commit cb53e8ef7dbddd81476e4e3730055f3778cd8c71
Comment 3 Srikanth Sankaran CLA 2013-03-12 02:04:22 EDT
Verified for 4.3 M6 using Build id: I20130310-2000