| Summary: | [null] safe annotation needed | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Ed Willink <ed> |
| Component: | Core | Assignee: | Stephan Herrmann <stephan.herrmann> |
| Status: | VERIFIED WORKSFORME | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | manoj.palat, stephan.herrmann |
| Version: | 4.6 | ||
| Target Milestone: | 4.6 M7 | ||
| Hardware: | PC | ||
| OS: | Windows NT | ||
| See Also: | https://bugs.eclipse.org/bugs/show_bug.cgi?id=490495 | ||
| Whiteboard: | |||
| Bug Depends on: | |||
| Bug Blocks: | 490494 | ||
|
Description
Ed Willink
Correction the message is irritating for List<T>. The message is useful for Reference<T> that I must annotate as @Nullable. Just need to be able to annotate List.get as 'safe'. Did you see the entry in M6 N&N [1] ? It explains how .eea can be used to address this. [1] https://www.eclipse.org/eclipse/news/4.6/M6/#null-analysis-generics (In reply to Stephan Herrmann from comment #2) > Did you see the entry in M6 N&N [1] ? > > It explains how .eea can be used to address this. > > [1] https://www.eclipse.org/eclipse/news/4.6/M6/#null-analysis-generics See the paragraph starting "The dilemma can be resolved by ..." (In reply to Stephan Herrmann from comment #3) > See the paragraph starting "The dilemma can be resolved by ..." Yes, it solves the primary use case, but is IMHO dangerously cute (and has no quickfix etc). Consider the consequence of adding new List<T> methods T firstElement() { return size() > 0 ? get(0) : null; } T firstElementOrDefault(T default) { assert default != null; return firstElement() != null ? firstElement() : default; } Now the dilemma is that get() needs to be safe but firstElement() needs to be @Nullable and firstElementOrDefault() needs to be @NonNull. (In reply to Ed Willink from comment #4) > (In reply to Stephan Herrmann from comment #3) > > See the paragraph starting "The dilemma can be resolved by ..." > > Yes, it solves the primary use case, but is IMHO dangerously cute (and has > no quickfix etc). Adding a quickfix is planned. > Consider the consequence of adding new List<T> methods > > T firstElement() { return size() > 0 ? get(0) : null; } > > T firstElementOrDefault(T default) { > assert default != null; > return firstElement() != null ? firstElement() : default; > } > > Now the dilemma is that get() needs to be safe but firstElement() needs to > be @Nullable and firstElementOrDefault() needs to be @NonNull. That's not a dilemma: add a .eea where get() remains untouched, firstElement() gets the @Nullable and firstElementOrDefault() gets the @NonNull. Where's a problem? (In reply to Stephan Herrmann from comment #5) > That's not a dilemma: add a .eea where get() remains untouched, > firstElement() gets the @Nullable and firstElementOrDefault() gets the > @NonNull. Where's a problem? Technically, none. A per-Operation absence of annotation has the flexibility. Editorially, "The dilemma can be resolved by adding a (possibly empty) external annotation file (.eea) to each affected library class. By using an empty annotation file, the user signals that all types in this class should be interpreted verbatim (like in the List case - use with care). " needs rewording to make clear that it is a per-Operation annotation absence that resolves a per-Operation dilemma, not a total absence ("empty annotation file") annotating everything. "By using an incomplete annotation file, the user signals that all unannotated types in unannotated declarations should be interpreted verbatim" (In reply to Ed Willink from comment #6) > (In reply to Stephan Herrmann from comment #5) > > That's not a dilemma: add a .eea where get() remains untouched, > > firstElement() gets the @Nullable and firstElementOrDefault() gets the > > @NonNull. Where's a problem? > > Technically, none. A per-Operation absence of annotation has the flexibility. > > Editorially, "The dilemma can be resolved by ... " needs rewording ... I'll try to resolve this in the user documentation. Verified for Eclipse Neon 4.6 M7 Build id: I20160425-1300 |