Skip to content
New issue

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

expression.unparsable accessing entrySet items after using record property accessor in Collectors.groupingBy #6520

Open
MichalStehlikCz opened this issue Apr 2, 2024 · 1 comment

Comments

@MichalStehlikCz
Copy link
Contributor

Following test case

class Test {

  private record Data(String value) {

  }

  Test(Collection<Data> data) {
    data.stream().collect(Collectors.groupingBy(Data::value))
        .entrySet().stream()
        .filter(entry -> entry.getValue().size() > 1)
        .forEach(entry -> {
          throw new IllegalArgumentException("Duplicate value " + entry.getKey());
        });
  }
}

fails compilation with java: [expression.unparsable] Expression invalid in dependent type annotation: [error for expression: data.stream().collect(java.util.stream.Collectors.groupingBy(Data::value)); error: Invalid 'Data::value' because class com.github.javaparser.ast.expr.MethodReferenceExpr is not a supported expression]

on line

        .filter(entry -> entry.getValue().size() > 1)

It is expected to compile without warnings

@jyoo980
Copy link
Contributor

jyoo980 commented Apr 6, 2024

Here's a (partially) minimized test case with the necessary imports and the command to execute the Checker Framework

import java.util.stream.Collectors;
import java.util.Collection;

class Test {

  private record Data(String value) { }

  Test(Collection<Data> data) {
    data.stream().collect(Collectors.groupingBy(Data::value))
      .entrySet().stream()
      .filter(entry -> entry.getValue().size() > 1);
  }
}

Command

javac \
-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
-processorpath $CHECKERFRAMEWORK/checker/dist/checker.jar \
-cp $CHECKERFRAMEWORK/checker/dist/checker-qual.jar \
-processor org.checkerframework.checker.nullness.NullnessChecker Test.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants