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

javac fails to compile code after JDK-8232933

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3
    • 24
    • None
    • tools

    Description

      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
      ```

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: