|
|
Re: Eclipse Nullness warning (after Java8) [message #1385764 is a reply to message #1385763] |
Wed, 11 June 2014 02:13   |
Eclipse User |
|
|
|
To my best knowledge, Java8 brought "type" qualifiers, which changed the location (and meaning) of some annotations.
Java7:
@NonNull String [] temp; // temp array cannot be null, we don't know anything about its contents.
Note that with Java7, there was no way to describe/check the nullness of the elements of an array, so the annotation way at the beginning.
Java8:
@NonNull String [] temp; // temp can be null, however if it is not null, its elements cannot be null.
Notice the location of the annotation. It comes before the type "String" so it qualifies String rather than the array. String in this instance represents the elements of the array.
String @NonNull [] temp; // temp cannot be null, we don't know anything about its elements (same as Java7)
Again, notice the place of the annotation. It comes before the array declaration ([]) hence qualifies it.
@NonNull String @NonNull [] temp; // temp cannot be null and its elements cannot be null, too.
I am pretty confident, but I might be missing something, please let me know if this is the case.
Thanks,
|
|
|
Re: Eclipse Nullness warning (after Java8) [message #1385769 is a reply to message #1385764] |
Wed, 11 June 2014 02:57   |
Eclipse User |
|
|
|
Kivanc,
Okay, it was a dumb question of mine then. No doubt a highly qualified
JDT expert will take note...
On 11/06/2014 8:13 AM, Kivanc Muslu wrote:
> To my best knowledge, Java8 brought "type" qualifiers, which changed
> the location (and meaning) of some annotations.
>
> Java7:
>
> @NonNull String [] temp; // temp array cannot be null, we don't know
> anything about its contents.
>
> Note that with Java7, there was no way to describe/check the nullness
> of the elements of an array, so the annotation way at the beginning.
>
> Java8:
>
> @NonNull String [] temp; // temp can be null, however if it is not
> null, its elements cannot be null.
>
> Notice the location of the annotation. It comes before the type
> "String" so it qualifies String rather than the array. String in this
> instance represents the elements of the array.
>
>
> String @NonNull [] temp; // temp cannot be null, we don't know
> anything about its elements (same as Java7)
>
> Again, notice the place of the annotation. It comes before the array
> declaration ([]) hence qualifies it.
>
>
> @NonNull String @NonNull [] temp; // temp cannot be null and its
> elements cannot be null, too.
>
>
> I am pretty confident, but I might be missing something, please let me
> know if this is the case.
> Thanks,
|
|
|
Re: Eclipse Nullness warning (after Java8) [message #1385952 is a reply to message #1385769] |
Thu, 12 June 2014 08:52  |
Eclipse User |
|
|
|
Sadly this is a simple bug in our implementation: for one particular case we are not correctly combining the information from annotations with results from flow analysis (happens when provided type is an array type with no null annotations at all and expected type requires @NonNull only at the outermost array type).
Bug filed (with draft patch): https://bugs.eclipse.org/437270
While it's too late for Luna, this'll be my first fix after release, a good candidate for 4.4.1, actually.
For the time being I'd suggest to add this to the declaration of 'temp':
@SuppressWarnings("null") // see https://bugs.eclipse.org/437270
sorry for the inconvenience,
Stephan
|
|
|
Powered by
FUDForum. Page generated in 0.04296 seconds