Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8324860

javac fails to compile code after JDK-8232933

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • 25
    • None
    • tools

      This class fails to compile in all JDKs with the commit that fixed JDK-8232933

      ```
      import java.util.Set;
      import java.util.TreeSet;
      import java.util.concurrent.Callable;
      import java.util.stream.Collectors;
      import java.util.stream.Stream;

      public class Reproducer {
          public static void main(String[] args){
              interface Interface {
                  <T> void runFun(T result, Callable<T> work);
              }
              Interface obj = null;

              obj.runFun(Set.of(), () -> Set.of("works"));
              obj.runFun(Set.of(), () -> new TreeSet<>(Set.of("works")));
              obj.runFun(Set.of(), () -> Stream.of("works").collect(Collectors.toSet()));
              obj.runFun(Set.of(), () -> Stream.of("broken in 17.0.10").collect(Collectors.toCollection(TreeSet::new))); // fails to compile
          }
      }
      ```

      The error reads:
      ```
      javac Reproducer.java
      Reproducer.java:19: error: method runFun in interface Interface cannot be applied to given types;
              obj.runFun(Set.of(), () -> Stream.of("broken in 17.0.10").collect(Collectors.toCollection(TreeSet::new)));
                 ^
        required: T,Callable<T>
        found: Set<Object>,()->Stream[...]new))
        reason: inferred type does not conform to equality constraint(s)
          inferred: C
          equality constraints(s): R
        where T,C,R are type-variables:
          T extends Object declared in method <T>runFun(T,Callable<T>)
          C extends Collection<String>
          R extends Collection<String>
      1 error
      ```

            vromero Vicente Arturo Romero Zaldivar
            vromero Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: