Community
Participate
Working Groups
I've declared these three annotations (but any other probably does the trick): // ------------------------------------- package p; import java.lang.annotation.ElementType; import java.lang.annotation.Target; @Target(ElementType.TYPE_USE) public @interface NotNull {} // ------------------------------------- package p; import java.lang.annotation.ElementType; import java.lang.annotation.Target; @Target(ElementType.TYPE_USE) public @interface NotNullByDefault {} // ------------------------------------- package p; import java.lang.annotation.ElementType; import java.lang.annotation.Target; @Target(ElementType.TYPE_USE) public @interface Nullable {} // ------------------------------------- Now, when I enable annotation based null analysis and violation of null specification, then the following doesn't compile: // ------------------------------------- package p; import java.util.ArrayList; import java.util.List; import java.util.function.Function; public class Test { <T> void m1(Function<? super Test, ? extends T> f) { } void m2() { m1(Test::m3); m1(t -> t.m3()); } @NotNull List<?> m3() { return new ArrayList<>(); } } // ------------------------------------- There's an error on the method reference that doesn't appear on the lambda: > Null type mismatch at method return type: Method descriptor Function<Test,List<capture#1-of ?>>.apply(Test) promises '@NotNull List<capture#of ?>' but referenced method provides '@NotNull List<?>' The error disappears when I'm not using wildcards. Both of these work: // ------------------------------------- package p; import java.util.ArrayList; import java.util.List; import java.util.function.Function; public class Test<X> { <T> void m1(Function<? super Test<?>, ? extends T> f) { } void m2() { m1(Test::m3); m1(t -> t.m3()); } @NotNull List<X> m3() { return new ArrayList<>(); } } // ------------------------------------- package p; import java.util.ArrayList; import java.util.List; import java.util.function.Function; public class Test { <T> void m1(Function<? super Test, ? extends T> f) { } void m2() { m1(Test::m3); m1(t -> t.m3()); } <X> @NotNull List<X> m3() { return new ArrayList<>(); } } // -------------------------------------
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.