Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 431722

Summary: [compiler][null] Warnings not reported for objects not initialized
Product: [Eclipse Project] JDT Reporter: shankha banerjee <shankhba>
Component: CoreAssignee: shankha banerjee <shankhba>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: manoj.palat, shankhba, stephan.herrmann
Version: 4.4   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description shankha banerjee CLA 2014-04-01 11:20:34 EDT
Please See: 

Bug 429906, Comment 2
Bug 429906, Comment 3
Bug 429906, Comment 4
Bug 429906, Comment 12

import org.eclipse.jdt.annotation.NonNullByDefault;

@NonNullByDefault
class Y {}
public class X {
	Y y, y1, y2 = new Y();
	Y[] y3, y4, y5 = new Y[0];
	X() {
	  y1 = new Y();
	  y4 = new Y[0];
	}  
	void foo() {
		bar (y);   // Warning should be reported here.
		bar (y1);
		bar (y2);
		bar2 (y3);  // Warning should be reported here.
		bar2 (y4);
		bar2 (y5);
	}
	private void bar(Y y) {}
	private void bar2(Y[] y) {}
}

--------------------------------------------

Warnings should not be reported for other cases, mentioned in the test case.
Comment 1 shankha banerjee CLA 2014-04-01 11:21:35 EDT
Please assign it to me.
Comment 2 Stephan Herrmann CLA 2014-04-03 17:01:12 EDT
I thought we discussed that the *initialization* is to be flagged,
i.e., either a field initializer or all constructors must assign non-null.

Problems should be / are flagged against the field or the constructor.

Why are you investigating *usage* of these fields?

If @NonNullByDefault applies to the field (is this 1.7- or 1.8??)
then each use of the field will consider it as @NonNull.

The main bug is: @NonNullByDefault is applied on Y, only, not on X.
Once corrected, which bug are you seeing (apart from bug 429906)?
Comment 3 shankha banerjee CLA 2014-04-03 21:37:49 EDT
(In reply to Stephan Herrmann from comment #2)
> I thought we discussed that the *initialization* is to be flagged,
> i.e., either a field initializer or all constructors must assign non-null.
> 
> Problems should be / are flagged against the field or the constructor.
> 
> Why are you investigating *usage* of these fields?
> 
> If @NonNullByDefault applies to the field (is this 1.7- or 1.8??)
> then each use of the field will consider it as @NonNull.
> 

Sorry. Bug 429906, Comment 3 does specify that error has to be reported on initialization. If we start reporting on usage the workspace will have lot of warning messages.

So the bug is: 

@NonNullByDefault
class Y {}
public class X {
    Y y;                  // Warning should be reported here.
    Y[] y1;               // Warning should be reported here.
    void bar() {
         y = new Y();
         y1 = new Y[0];
    }
}

> The main bug is: @NonNullByDefault is applied on Y, only, not on X.
> Once corrected, which bug are you seeing (apart from bug 429906)?

Nothing else other than this bug.

The Bug 429906 was originally supposed to handle this case. I went ahead and solved the array initialization issue on that bug.

Thanks
Comment 4 shankha banerjee CLA 2014-04-03 23:55:10 EDT

*** This bug has been marked as a duplicate of bug 431965 ***