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

Bug 438012

Summary: [1.8][null] Bogus Warning: The nullness annotation is redundant with a default that applies to this location
Product: [Eclipse Project] JDT Reporter: Clovis Seragiotto <clovis.seragiotto>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: clovis.seragiotto, srikanth_sankaran, stephan.herrmann
Version: 4.4   
Target Milestone: 4.5 M1   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 438458    

Description Clovis Seragiotto CLA 2014-06-24 05:32:22 EDT
For the program below (which has no nullness annotation except for @NonNullByDefault), the compiler issues the warning "The nullness annotation is redundant with a default that applies to this location"

import org.eclipse.jdt.annotation.NonNullByDefault;
import static org.eclipse.jdt.annotation.DefaultLocation.*;

@NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT, TYPE_PARAMETER })
interface Bar<V> {
    V getV();
}

By choosing the quick fix "remove redundant nullness annotation", one gets:
An exception occurred while applying the quick fix: The fix 'Remove redundant nullness annotation' generated a null change.
Comment 1 Clovis Seragiotto CLA 2014-06-27 04:20:03 EDT
In fact, 
@NonNullByDefault({ RETURN_TYPE, TYPE_PARAMETER })
suffices to reproduce the error.
Comment 2 Stephan Herrmann CLA 2014-07-22 09:56:04 EDT
I have a fix under test:

By using a default for TYPE_PARAMETER, V is a nonnull type. When we fill in the defaults for the signature of getV() we find:
- the return type is already nonnull
- a nonnull default shall be applied to the return type
This _looks_ like redundant specification.

Fixed by checking whether the method return has an explicit annotation (AST). Since the parser associates top-level return annotations to the method, that's where we actually look.
Similar change is also made for parameters.
Comment 4 Srikanth Sankaran CLA 2014-08-05 05:20:30 EDT
Verified for 4.5 M1 using 
Version: Mars (4.5)
Build id: I20140804-2000