| Summary: | [null][1.8] Bogus warning with NonNullByDefault | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Clovis Seragiotto <clovis.seragiotto> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED MOVED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | manoj.palat, stephan.herrmann |
| Version: | 4.7 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| See Also: | https://github.com/eclipse-jdt/eclipse.jdt.core/issues/682 | ||
| Whiteboard: | |||
Here's what I see in HEAD: As shown in comment 0 the return statement has this warning: Null type safety (type annotations): The expression of type 'Set<String @NonNull[]>' needs unchecked conversion to conform to '@NonNull Collection<String @NonNull[]>', corresponding supertype is 'Collection<String @NonNull[]>' This concerns the toplevel type Set. This can be fixed using an external @NonNull annotation on the return of Collections.singleton(). After that, removing either the second or third annotation in the line above, makes a new warning appear: Null type safety (type annotations): The expression of type '@NonNull String []' needs unchecked conversion to conform to 'String @NonNull[]' Not only is this warning wrong, also showing the same warning in both cases looks bogus. Next when I replace the @NNBD by spelling out: Collection<@NonNull String @NonNull[]> from(..) I get no warning even with the second annotation on the parameter removed. bulk move out of 4.8 Bulk move out of 4.9 . 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. Over to github: https://github.com/eclipse-jdt/eclipse.jdt.core/issues/682 |
In the following class, one gets the warning: "The nullness annotation is redundant with a default that applies to this location", which is right. import static org.eclipse.jdt.annotation.DefaultLocation.*; import org.eclipse.jdt.annotation.*; import java.util.*; class Foo { @NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS }) static Collection<String[]> from(@NonNull String @NonNull [] @NonNull... elements) { // <-- warning here, ok return Collections.singleton(elements[0]); <-- warning here if any @NonNull is removed } } If, however, any of the redundant @NonNull annotations is removed, one gets another warning about null type safety ("the expression needs unchecked conversion")