|
|
|
Newsgroup discussions lead to two slightly different suggestions:
1) Treat non-annotated variables exactly as @Nullable variables are treated now. If you do this without further heuristics, then even System.out.println("") will trigger an NPE warning, because System.out is non-annotated and would be assumed to be @Nullable. You'd have to place this within "if (System.out != null)". 2) Only treat non-annotated variables differently in an assignment to a @NotNull variable. This will only trigger warnings in those parts of your code that you've actually annotated with @NotNull, that is, those parts where you've explicitly stated that you want a warning if the variable might ever be assigned the value null. This is the behaviour I would like to see (I think...). I definitely prefer the #2 option, above. I mostly view the "@Nullable" annotation as a comment to the person writing code. In general, the compiler should assume that anything not declared @NotNull is nullable, but it should only warn about cases where:
1) A @Nullable variable is used in a context where it must not be null, such as a method call. 2) A @Nullable or unannotated variable is assigned to a @NotNull variable. See also the related bug http://www.jetbrains.net/jira/browse/IDEA-2436 It looks like/has a lot in common with :
"@Nullable inspection improvement" http://www.jetbrains.net/jira/browse/IDEA-2051 Alain Any chance of seeing this in an update to IDEA 5.0? It would make @Nullable and @NotNull much more useful and it seems like it wouldn't be too difficult to implement in IDEA, while a plugin would have to re-implement all of your dataflow analysis code in order to avoid too many false positives. If it hadn't been for the dataflow problem, I'd do it myself...
Bill Pugh is talking about a @DefaultAnnotation(@NotNull) approach, to annotate a class or package. I think it's too restrictive; I'd rather @DefaultMethodNullness(NOT_NULL) or something, to specify nullness for only methods, and using an enum instead of the annotations themselves.
In 5.1 - very unlikely. In Demetra - quite possible, but I'm not sure.
It looks like/has a lot in common with :
"@Nullable inspection improvement" http://www.jetbrains.net/jira/browse/IDEA-2051 Alain It looks like/has a lot in common with :
"@Nullable inspection improvement" http://www.jetbrains.net/jira/browse/IDEA-2051 Alain Also see IDEABKL-4194.
The current implementation of @NotNull is not reliable, because there is no warning when an unannotated value is assigned to it, so it can't really be trusted. I would very much love to see some action on this as soon as possible! I'm trying to use @Nullable and @NotNull extensively in a program, and the lack of this feature is causing problems. It looks like/has a lot in common with :
"@Nullable inspection improvement" http://www.jetbrains.net/jira/browse/IDEA-2051 Alain It looks like/has a lot in common with :
"@Nullable inspection improvement" http://www.jetbrains.net/jira/browse/IDEA-2051 Alain |
|||||||||||||||||||||||||||||||||||||||||||||||||
"@Nullable inspection improvement"
http://www.jetbrains.net/jira/browse/IDEA-2051
Alain