We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Consider the following classes:
MapEntryGetValueWorks:
MapEntryGetValueWorks
import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentMap; import java.util.stream.Collectors; import java.util.stream.IntStream; public class MapEntryGetWorks { public static void main(String[] args) { ConcurrentMap<Integer, List<List<Integer>>> m = IntStream.range(0, 100) .mapToObj(i -> List.of(i, i % 2)) .collect(Collectors.groupingByConcurrent(l -> ((List<Integer>) l).get(1))); ArrayList<Integer> list = m.entrySet() .stream() .sorted(Map.Entry.comparingByKey()) .mapToInt(Map.Entry::getKey) .collect(ArrayList::new, ArrayList::add, ArrayList::addAll); } }
and MapEntryGetFails
MapEntryGetFails
import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; public class MapEntryGetFails { public static void main(String[] args) { ArrayList<Integer> list = IntStream.range(0, 100) .mapToObj(i -> List.of(i, i % 2)) .collect(Collectors.groupingByConcurrent(l -> ((List<Integer>) l).get(1))) .entrySet() .stream() .sorted(Map.Entry.comparingByKey()) .mapToInt(Map.Entry::getKey) .collect(ArrayList::new, ArrayList::add, ArrayList::addAll); } }
They do the same thing, but the Works one split the code in two statements, which is not really needed.
Works
When running ~/checker-framework-3.35.0/checker/bin/javac -processor Nullness src/main/java/MapEntryGetWorks.java, I get no errors.
~/checker-framework-3.35.0/checker/bin/javac -processor Nullness src/main/java/MapEntryGetWorks.java
When running ~/checker-framework-3.35.0/checker/bin/javac -processor Nullness src/main/java/MapEntryGetFails.java, I get
~/checker-framework-3.35.0/checker/bin/javac -processor Nullness src/main/java/MapEntryGetFails.java
src/main/java/MapEntryGetFails.java:16: error: [methodref.return] Incompatible return type .mapToInt(Map.Entry::getKey) ^ found : /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object required: @Initialized @NonNull int Consequence: method in @Initialized @NonNull Entry</*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object, /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object> /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object getKey(@Initialized @NonNull Entry</*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object, /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object> this) is not a valid method reference for method in @Initialized @NonNull ToIntFunction<@Initialized @NonNull Entry</*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object, /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object>> @Initialized @NonNull int applyAsInt(@Initialized @NonNull ToIntFunction<@Initialized @NonNull Entry</*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object, /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object>> this, @Initialized @NonNull Entry</*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object, /*INFERENCE FAILED for:*/ ? extends @Initialized @Nullable Object> p0) 1 error
One can build similar error cases using Map.Entry::getValue instead of getKey.
Map.Entry::getValue
getKey
I'm not sure if it is a bug.
The text was updated successfully, but these errors were encountered:
This test case now passes in master.
Sorry, something went wrong.
smillst
No branches or pull requests
Consider the following classes:
MapEntryGetValueWorks
:and
MapEntryGetFails
They do the same thing, but the
Works
one split the code in two statements, which is not really needed.When running
~/checker-framework-3.35.0/checker/bin/javac -processor Nullness src/main/java/MapEntryGetWorks.java
, I get no errors.When running
~/checker-framework-3.35.0/checker/bin/javac -processor Nullness src/main/java/MapEntryGetFails.java
, I getOne can build similar error cases using
Map.Entry::getValue
instead ofgetKey
.I'm not sure if it is a bug.
The text was updated successfully, but these errors were encountered: