| Summary: | [1.8][null] Bogus error/warning when DefaultLocation.TYPE_PARAMETER is added to NonNullByDefault | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Clovis Seragiotto <clovis.seragiotto> |
| Component: | Core | Assignee: | Till Brychcy <register.eclipse> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | register.eclipse, stephan.herrmann |
| Version: | 4.5 | ||
| Target Milestone: | 4.7 M4 | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| See Also: | https://bugs.eclipse.org/bugs/show_bug.cgi?id=501564 | ||
| Whiteboard: | |||
reproduced, thanks. Too much on my plate for 4.6. Bulk deferral to 4.7 Another simple test case:
import java.util.EnumMap;
import org.eclipse.jdt.annotation.*;
@NonNullByDefault(DefaultLocation.TYPE_PARAMETER)
public class Foo<E extends Enum<E>> {
Foo(Class<E> c) {
new EnumMap<>(c);
}
}
Error (only if null analysis is on): Cannot infer type arguments for EnumMap<>
… and also:
import java.util.function.Function;
import org.eclipse.jdt.annotation.*;
@NonNullByDefault(DefaultLocation.TYPE_PARAMETER)
public class Foo<E extends Enum<E>> {
Foo(Class<E> c) {
Function<E, String> f = Enum::name; // unexpected error: The type Enum does not define name(E) that is applicable here
Function<E, String> g = (E e) -> e.name(); // unexpected error: The method name() is undefined for the type E
}
}
The "main" bug from comment #0 has been fixed by the fix for bug 501031, which is included in 4.7M3 The examples from comment #3 and comment #4 are different, but they also have been already been fixed by the fix for bug 501564, included in 4.7M4 *** This bug has been marked as a duplicate of bug 501031 *** |
This class compiles without errors or warnings... @NonNullByDefault public interface Foo<@NonNull A> { // # static <@NonNull B> Foo<B> newInstance(B b) { // * throw new UnsupportedOperationException("for " + b); } } ... while for the following class... /** * @param <A> Comment */ @NonNullByDefault({PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT, TYPE_PARAMETER}) public interface Foo<A> { static <B> Foo<B> newInstance(B b) { throw new UnsupportedOperationException("for " + b); } } ... the compiler complains: 1) The type 'B' is not a valid substitute for the type parameter '@NonNull A' (line *) 2) Unused type parameter A (line #) The quick fixes for 2 are also invalid: - remove unused type parameter - document type parameter to avoid 'unused' warning