Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 402993 - [null] Follow up of bug 401088: Missing warning about redundant null check
Summary: [null] Follow up of bug 401088: Missing warning about redundant null check
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.3 M7   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-12 03:57 EDT by Srikanth Sankaran CLA
Modified: 2013-04-30 07:35 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 Srikanth Sankaran CLA 2013-03-12 03:57:06 EDT
Why would we not issue warnings on the two lines called out ??

// ---
public class NPEonCast {

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

	private static void open() throws Exception {
		occasionallyThrowException();
	}

	private static void close() throws Exception {
		occasionallyThrowException();
	}

	public static void main(String s[]) {
		Exception exc = null;
		if (exc == null)
			;
		try {
			open();
			// do more things
		}
		catch (Exception e) {
			if (exc == null) // no warning here ??
				;
		}
		finally {
			try {
				close();
			}
			catch (Exception e) {
				if (exc == null) // No warning here ??
					exc = e;
			}
		}
	}
}
Comment 1 Stephan Herrmann CLA 2013-03-12 10:05:01 EDT
I'll take a fresh look for M7, thanks.
Comment 2 Stephan Herrmann CLA 2013-04-13 03:33:17 EDT
The fix reconciles concepts introduced in bug 345305 and bug 401088:

Bug 345305 introduced FlowContext.markFinallyNullStatus(), mergeFinallyNullInfo(), conditionalLevel in order to feed null info (not def.assign) into the catch & finally blocks.

Bug 401088 made sure this information is shared in nested try-finally structures.

Unfortunately, real sharing of initsOnFinally caused undesired side effects. 
To fix this I replaced sharing of flowInfos with some new wiring of floxContexts using a new field outerTryContext.
markFinallyNullStatus now delegates to the outerTryContext if set. 
To accommodate the new field outerTryContext and its evaluation a new class TryFlowContext has been fitted into the hierarchy above FinallyFlowContext and InsideSubRoutineFlowContext.

I also had to fine tune when methods mergeFinallyNullInfo / markFinallyNullInfo would be effective:
- don't record any initsOnFinally during analysis of the finally block itself (would otherwise appear to affect the catch blocks)
- while analyzing catch blocks consider the null info as conditionally affecting the finally block
Comment 3 Manoj N Palat CLA 2013-04-30 04:12:14 EDT
Verified for 4.3 M7 build id: I20130428-2000