-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Incomplete" annotations #116
Comments
I'm still learning Eclipse's NP analysis but I think eclipse not inferring that:
is correct logic. This is because Anyway assuming you want to convert a stream to
|
How could that be inverse logic? |
Sorry for the late reply. I'm still figuring out how the inference is done for Eclipse NP but from a purely type semantics and inverse logic I meant you could write:
So how would eclipse know the above is NonNull given we "not" it twice. Even Kotlin or Scala would have problems with this.
That being said I don't understand how Eclipse will infer some object is nonNull if I do this: Some object = .... some @Nullable function;
requireNonNull(object); // normally one would do object = requireNonNull(object)
object.stuff(); //this should still be a warning but for some reason Eclipse infers now that object is NonNull without the assignment. That is from above in my mind object is still |
I guess Eclipse does additional null analysis on attached source libraries such that
It seems to get this analysis you need it be an actual source library and not say a maven dependency. For example I can't write a |
@J-N-K Actually you are right about:
I couldn't understand how the Objects.* methods could have complete null analysis. My understanding was just type based (ie annotation attached to types). However ostensible there is an internal whitelist of methods that the JDT will then assume the input parameter will be I looked at the EEA format to see if you could define such methods as the ones in Object.* and it doesn't appear so which is strange because those methods are still defined in the EEA augments library. |
E.g.
Map.computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
:The return value is either the
@NonNull
value already present in the map or the result ofmappingFunction
, which is allowed to returnnull
. Then the return-value ofcomputeIsAbsent
is alsonull
. Our current annotation isWhich is in general correct. However the eclipse compiler is not able to infer
@NonNull
if themappingFunction
has a@NonNull
return value, e.g.Map.computeIfAbsent(key, k -> new Foo());
.is not working, because then
return Map.computeIfAbsent(key, k -> null);
passes, even if the return-value of the method is annotated@NonNull
.is not working either, because then the compiler requires the
mappingFunction
to have a@NonNull
return value.Another problem is that
Stream<@NonNull T> = Stream<@Nullable T>.filter(Objects::nonNull);
is not working, because the compiler is not able to detect that all
null
-objects will be filtered by.filter(Objects::nonNull)
.Has anyone any idea how to solve that?
The text was updated successfully, but these errors were encountered: