import java.util.Map;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.IntStream;
import org.checkerframework.checker.nullness.qual.Nullable;
public abstract class Test {
public Map<String, Object> test(List<String> ids) {
return IntStream.range(0, ids.size())
.boxed()
.collect(collector(ids::get, i -> new Object()));
}
protected abstract <T extends @Nullable Object, K, V>
Collector<T, ?, Map<K, V>> collector(
Function<? super T, ? extends K> keyFunction,
Function<? super T, ? extends V> valueFunction);
}
outputs
Note: The Checker Framework is tested with JDK 8, 11, 17, and 21. You are using version 22.
Test.java:12: error: [methodref.param.invalid] Incompatible parameter type for arg0
.collect(collector(ids::get, i -> new Object()));
^
found : @NonNull int
required: /*INFERENCE FAILED for:*/ ? extends @Nullable Object
Consequence: method in @NonNull List<@NonNull String>
@NonNull String get(@NonNull List<@NonNull String> this, @NonNull int p0)
is not a valid method reference for method in @NonNull Function</*INFERENCE FAILED for:*/ ? extends @Nullable Object, @NonNull String>
@NonNull String apply(@NonNull Function</*INFERENCE FAILED for:*/ ? extends @Nullable Object, @NonNull String> this, /*INFERENCE FAILED for:*/ ? extends @Nullable Object p0)
1 error
notes
Can be fixed by replacing ids::get with i -> ids.get(i)
Tested with latest release 3.42.0-eisop3.
commands
./checker/bin/javac -processor nullness Test.java
inputs
Test.java
outputs
notes Can be fixed by replacing
ids::get
withi -> ids.get(i)