Community
Participate
Working Groups
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).
New Gerrit change created: https://git.eclipse.org/r/62868
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
Gerrit change https://git.eclipse.org/r/62868 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=7d01bb096ac46fff53b05394abe6dea72ecf0fca
*** This bug has been marked as a duplicate of bug 481332 ***
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