Bug 466969 - [1.8][null] With @NonNull Type Bounds: The type '?' is not a valid substitute...
Summary: [1.8][null] With @NonNull Type Bounds: The type '?' is not a valid substitute...
Status: VERIFIED DUPLICATE of bug 481332
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 4.6 M4   Edit
Assignee: Till Brychcy CLA
QA Contact: Stephan Herrmann CLA
URL:
Whiteboard:
Keywords: test
Depends on:
Blocks:
 
Reported: 2015-05-11 04:39 EDT by Till Brychcy CLA
Modified: 2015-12-16 16:48 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 Till Brychcy CLA 2015-05-11 04:39:21 EDT
DESCRIPTION:
With Java8 TYPE_USE Annotations:

public abstract class GenericType<T extends @org.eclipse.jdt.annotation.NonNull Runnable> {
	abstract T get();
}
—
import static org.eclipse.jdt.annotation.DefaultLocation.*;
@org.eclipse.jdt.annotation.NonNullByDefault({ARRAY_CONTENTS,FIELD,PARAMETER,RETURN_TYPE,TYPE_ARGUMENT,TYPE_BOUND,TYPE_PARAMETER})
public class WildcardUsage {
	void fails(GenericType<?> p) {p.get().run();}
	void works(GenericType<@org.eclipse.jdt.annotation.NonNull ?> p) {p.get().run();}
}

Leads to the Error Message for them method „fails":
Null constraint mismatch: The type '?' is not a valid substitute for the type parameter 'T extends @NonNull Runnable'

As I understand the Wildcard operator, it should get the @NonNull from GenericType (just as it gets "extends Runnable")

As you can see, no possible value of DefaultLocation with NonNullByDefault at "Usage" fixes this.

Especially, if @NonNullByDefault with no args is used in GenericType, this error appears, because the default includes DefaultLocation.TYPE_BOUND,
which means that this problem is quite annoying.

Possible Workarounds:
- Add @NonNull in front of every single Wildcard usage, like in method „works“ 
- Remove DefaultLocation.TYPE_BOUND from the default value of NonNullByDefault. (which is what we do).
Comment 1 Eclipse Genie CLA 2015-12-16 14:49:59 EST
New Gerrit change created: https://git.eclipse.org/r/62868
Comment 2 Till Brychcy CLA 2015-12-16 14:56:04 EST
This bug has been fixed by the changes for bug 481332 :-)

I've sent the previously broken example from this bug as testcase via gerrit
Comment 4 Stephan Herrmann CLA 2015-12-16 16:46:19 EST

*** This bug has been marked as a duplicate of bug 481332 ***
Comment 5 Stephan Herrmann CLA 2015-12-16 16:48:20 EST
Thanks Till, nice one :)

Marking as verified after checking that the code from comment 0 indeed still raises an error in 4.6 M3 but is accepted in 4.6 M4