JDK-8055681 : Javac unable to resolve method
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u20
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2014-08-20
  • Updated: 2014-08-20
  • Resolved: 2014-08-20
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
Given the following Testcase:

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

public class TestClass<E>
{
    private Collection<E> coll;

    public void addAll(final Collection<? extends E> c) {
        coll.addAll(c.stream().collect(Collectors.toList()));
    }
}

My expected behaviour is for this to compile correctly, which it does in Java 8 u5 and u11. If you try and compile this class with javac from u20 then it is unable to find the collect() override correctly. Failing with the following error message.

TestClass.java:9: error: no suitable method found for collect(Collector<Object,CAP#1,List<Object>>)
        coll.addAll(c.stream().collect(Collectors.toList()));
                              ^
    method Stream.<R#1>collect(Supplier<R#1>,BiConsumer<R#1,? super CAP#2>,BiConsumer<R#1,R#1>) is not applicable
      (cannot infer type-variable(s) R#1
        (actual and formal argument lists differ in length))
    method Stream.<R#2,A>collect(Collector<? super CAP#2,A,R#2>) is not applicable
      (cannot infer type-variable(s) R#2,A,CAP#3,T#2
        (argument mismatch; Collector<CAP#2,CAP#4,List<CAP#2>> cannot be converted to Collector<? super CAP#2,CAP#4,List<CAP#2>>))
  where R#1,T#1,E,R#2,A,T#2 are type-variables:
    R#1 extends Object declared in method <R#1>collect(Supplier<R#1>,BiConsumer<R#1,? super T#1>,BiConsumer<R#1,R#1>)
    T#1 extends Object declared in interface Stream
    E extends Object declared in class TestClass
    R#2 extends Object declared in method <R#2,A>collect(Collector<? super T#1,A,R#2>)
    A extends Object declared in method <R#2,A>collect(Collector<? super T#1,A,R#2>)
    T#2 extends Object declared in method <T#2>toList()
  where CAP#1,CAP#2,CAP#3,CAP#4 are fresh type-variables:
    CAP#1 extends Object from capture of ?
    CAP#2 extends E from capture of ? extends E
    CAP#3 extends Object from capture of ?
    CAP#4 extends Object from capture of ?
1 error
Comments
Yes, the test works perfectly well on current jdk8u, therefore the issue is a duplicate for an already fixed issue.
20-08-2014

This is a backport of the alleged fix, which was too late for 8u20, but is already fixed in 8u40: https://bugs.openjdk.java.net/browse/JDK-8051454
20-08-2014

Possible duplicate for JDK-8039214.
20-08-2014

Reproduced with 8u20 EA: $ java -version java version "1.8.0_20-ea" Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b23) Java HotSpot(TM) 64-Bit Server VM (build 25.20-b22, mixed mode)
20-08-2014

Also fails on publicly-released 8u20: $ java -version java version "1.8.0_20" Java(TM) SE Runtime Environment (build 1.8.0_20-b26) Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode) Same workaround works.
20-08-2014

Correct priority.
20-08-2014

It helps to add <E> to static method: coll.addAll(c.stream().collect(Collectors.<E>toList())); ILW: HML => P2
20-08-2014