Bug 365836

Summary: [compiler][null] Incomplete propagation of null defaults.
Product: [Eclipse Project] JDT Reporter: Srikanth Sankaran <srikanth_sankaran>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, daniel_megert, markus.kell.r
Version: 3.8   
Target Milestone: 3.8 M5   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Srikanth Sankaran CLA 2011-12-07 03:26:30 EST
@NonNullByDefault applied at a method level does not get
propagated to the local types of the method. Either we need
to fix this or at least clarify semantics.

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

// @NonNullByDefault
public class X {
    @NonNullByDefault 
    public void foo(@Nullable String [] args) {
        class local {
            void zoo(Object o) {

            }
        };
        new local().zoo(null); // No error with defaults applying to foo
    }
}
Comment 1 Stephan Herrmann CLA 2011-12-07 04:46:34 EST
(In reply to comment #0)
> @NonNullByDefault applied at a method level does not get
> propagated to the local types of the method. Either we need
> to fix this or at least clarify semantics.

I opt for: "fix".
Scopes for these defaults should not have "holes".

Obviously enclosing methods are not considered while searching
for a default, but should be.
Comment 2 Markus Keller CLA 2011-12-07 07:28:09 EST
> I opt for: "fix".
+1
Comment 3 Stephan Herrmann CLA 2011-12-19 14:55:14 EST
Fix was straight-forward by respecting LocalTypeBinding.enclosingMethod when searching
for an applicable default.

Release for 3.8 M5 via commit 62b97f10b8bb4123dfea4bccabc125ecea6ba019
Comment 4 Srikanth Sankaran CLA 2012-01-24 09:50:54 EST
Verified for 3.8 M5 using build id: I20120122-2000