Bug 365835 - [compiler][null] inconsistent error reporting.
Summary: [compiler][null] inconsistent error reporting.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.8 M5   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-07 03:24 EST by Srikanth Sankaran CLA
Modified: 2012-01-24 09:53 EST (History)
1 user (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 2011-12-07 03:24:14 EST
3.8 M4 candidates.

In the following program both the assignment and return statement
are violating the null contracts in exactly the same way, but the
diagnostics are different. One is a warning and the other an error.
This is inconsistent:

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;


public class X {
	@NonNull
	public Object foo(Object x, int y) {
		@NonNull Object local;
		while (true) {
			if (y == 4) {
				local = x;  // error
				return x;   // only a warning.
			}
			x = null;
		}
	}
}
Comment 1 Stephan Herrmann CLA 2011-12-19 15:28:35 EST
Fixing was straight-forward:
ReturnStatement reported the nullity mismatch directly to the ProblemReporter
instead via the FlowContext, which is required to consider the enclosing loop.
By calling flowContext.recordNullityMismatch(..) reporting is deferred until
we have the necessary information from the loop.

I double checked that this was the last location taking this "shortcut",
now all reports properly go via the FlowContext.

Released for 3.8 M5 via commit 8e77108c42837d2f8e34e3f8fd4f8eea8e97b2f7
Comment 2 Srikanth Sankaran CLA 2012-01-24 09:53:08 EST
Verified for 3.8 M5 using build id: I20120122-2000