checker-framework
checker-framework copied to clipboard
type.arguments.not.inferred / crash using result of collect groupingBy
trafficstars
class Test {
private final int value;
Test(int value) {
this.value = value;
}
int getValue() {
return value;
}
static int merge(int value, Map<Integer, List<Test>> data) {
return value;
}
static void test(List<Test> externals) {
var testsByValue = Stream.of(new Test(1), new Test(2))
.collect(Collectors.groupingBy(Test::getValue));
var values = Stream.of(1, 2)
.map(
val -> merge(val, testsByValue))
.toList();
}
}
This leads to type.arguments.not.inferred, but I globally suppressed it and then it throws exception
java: StructuralEqualityComparer: unexpected combination: type: [TYPEVAR class org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedTypeVariable] capture#01 extends Object super Integer supertype: [DECLARED class org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedDeclaredType] Integer
visitHistory = org.checkerframework.framework.type.StructuralEqualityVisitHistory@391e565e
; The Checker Framework crashed. Please report the crash. Version: Checker Framework 3.46.0.
Compilation unit: /C:/Projects/pvyscomponents/java/libs/kernel/repository/api/src/main/java/com/provys/repository/Test.java
Last visited tree at line 36 column 26:
val -> merge(val, testsByValue))
Exception: java.lang.Throwable; java.lang.Throwable
at org.checkerframework.javacutil.BugInCF.<init>(BugInCF.java:26)
I believe problem is in inference of testsByValue type, as if var is replaced with Map<Integer, List<Test>>, code compiles without problem.
https://github.com/typetools/checker-framework/pull/6764 added a work around so that this code no longer crashes.