-
Notifications
You must be signed in to change notification settings - Fork 20
Description
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 of mappingFunction, which is allowed to return null. Then the return-value of computeIsAbsent is also null. Our current annotation is
computeIfAbsent
(TK;Ljava/util/function/Function<-TK;+TV;>;)TV;
(TK;L1java/util/function/Function<-TK;+T0V;>;)T0V;
Which is in general correct. However the eclipse compiler is not able to infer @NonNull if the mappingFunction has a @NonNullreturn value, e.g. Map.computeIfAbsent(key, k -> new Foo());.
computeIfAbsent
(TK;Ljava/util/function/Function<-TK;+TV;>;)TV;
(TK;L1java/util/function/Function<-TK;+T0V;>;)TV;
is not working, because then return Map.computeIfAbsent(key, k -> null); passes, even if the return-value of the method is annotated @NonNull.
computeIfAbsent
(TK;Ljava/util/function/Function<-TK;+TV;>;)TV;
(TK;L1java/util/function/Function<-TK;+TV;>;)TV;
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?