JDK-8154180 : Regression: stuck expressions do not behave correctly
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2016-04-13
  • Updated: 2018-01-17
  • Resolved: 2016-05-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b120Fixed
Related Reports
Relates :  
Relates :  
Description
Since the fix for JDK-8078093 there has been a regression in the behavior for stuck expressions. For example, this program fails to compile:

import java.util.function.Consumer;
import java.nio.ByteBuffer;

class Foo {
    Foo(Consumer<ByteBuffer> cb) {
    }

    public static void main(String[] args) {
        Foo foo = new Foo((b -> System.out.println(asString(b))));
    }

    static String asString(ByteBuffer buf) {
        return null;
    }
}

But compiles if the parenthesis are removed from around the lambda.

Also, this other program:

interface Foo1 {
   Object m(String s);
}

interface Foo2 {
   String m(String s);
}

class Test {
   void m(Foo1 f1) { }
   void m(Foo2 f2) { }

   void test() {
      m(x->"");
      m((x->""));
   }
}

Only reports one ambiguity error instead of two.
Comments
This problem is caused by the fact that stuck ArgumentTypes do not return the correct speculative type/tree: in fact, if an argument expression is stuck, the default DeferredType behavior wins and the overload check never occurs inside ArgumentType.
13-04-2016