checker-framework icon indicating copy to clipboard operation
checker-framework copied to clipboard

type.arguments.not.inferred / crash using result of collect groupingBy

Open MichalStehlikCz opened this issue 1 year ago • 1 comments
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.

MichalStehlikCz avatar Aug 12 '24 07:08 MichalStehlikCz

https://github.com/typetools/checker-framework/pull/6764 added a work around so that this code no longer crashes.

smillst avatar Sep 13 '24 17:09 smillst