JDK-8200564 : Parameter cannot accept a lambda returning a generic object with an inferred type
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9,10,11
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: linux_ubuntu
  • CPU: generic
  • Submitted: 2018-03-31
  • Updated: 2018-05-16
  • Resolved: 2018-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.
Other
tbd_majorResolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux waikin-Satellite-U300 3.2.0-126-generic #169-Ubuntu SMP Fri Mar 31 14:15:21 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
When using a lambda that returns an object that uses generic object into a function, the compiler throws an exception and requests the programmer to file a bug report. 



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following code:


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compile without error or an exception that does not asked to report as a compiler bug

ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (9.0.4). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.AssertionError: isSameType UNKNOWN
	at jdk.compiler/com.sun.tools.javac.code.Types$SameTypeVisitor.visitType(Types.java:1055)
	at jdk.compiler/com.sun.tools.javac.code.Types$SameTypeVisitor.visitType(Types.java:1027)
	at jdk.compiler/com.sun.tools.javac.code.Type.accept(Type.java:214)
	at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4614)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSameType(Types.java:1024)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSameType(Types.java:1019)
	at jdk.compiler/com.sun.tools.javac.code.Types.containsTypeEquivalent(Types.java:4277)
	at jdk.compiler/com.sun.tools.javac.code.Types.containsTypeEquivalent(Types.java:1369)
	at jdk.compiler/com.sun.tools.javac.code.Types$HasSameArgs.visitMethodType(Types.java:2982)
	at jdk.compiler/com.sun.tools.javac.code.Types$HasSameArgs.visitMethodType(Types.java:2967)
	at jdk.compiler/com.sun.tools.javac.code.Type$MethodType.accept(Type.java:1446)
	at jdk.compiler/com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4614)
	at jdk.compiler/com.sun.tools.javac.code.Types.hasSameArgs(Types.java:2964)
	at jdk.compiler/com.sun.tools.javac.code.Types.hasSameArgs(Types.java:2960)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSubSignature(Types.java:2499)
	at jdk.compiler/com.sun.tools.javac.code.Types.isSubSignature(Types.java:2495)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.overrides(Symbol.java:1808)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.overrides(Symbol.java:1780)
	at jdk.compiler/com.sun.tools.javac.code.Types$ImplementationCache.implementationInternal(Types.java:2683)
	at jdk.compiler/com.sun.tools.javac.code.Types$ImplementationCache.get(Types.java:2668)
	at jdk.compiler/com.sun.tools.javac.code.Types.implementation(Types.java:2703)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.implementation(Symbol.java:1880)
	at jdk.compiler/com.sun.tools.javac.code.Symbol$MethodSymbol.implementation(Symbol.java:1873)
	at jdk.compiler/com.sun.tools.javac.code.Types.firstUnimplementedAbstractImpl(Types.java:2819)
	at jdk.compiler/com.sun.tools.javac.code.Types.firstUnimplementedAbstractImpl(Types.java:2843)
	at jdk.compiler/com.sun.tools.javac.code.Types.firstUnimplementedAbstract(Types.java:2802)
	at jdk.compiler/com.sun.tools.javac.comp.Check.checkAllDefined(Check.java:2153)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4507)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4454)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4383)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitClassDef(Attr.java:946)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:774)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:723)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitAnonymousClassDefinition(Attr.java:2302)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.lambda$visitAnonymousClassDefinition$2(Attr.java:2261)
	at jdk.compiler/com.sun.tools.javac.comp.InferenceContext.notifyChange(InferenceContext.java:265)
	at jdk.compiler/com.sun.tools.javac.comp.InferenceContext.notifyChange(InferenceContext.java:256)
	at jdk.compiler/com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:248)
	at jdk.compiler/com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:604)
	at jdk.compiler/com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:643)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3998)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3791)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3698)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3677)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.checkId(Attr.java:3664)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3549)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2104)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1911)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1628)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:700)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1678)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1446)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:723)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:742)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1203)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1014)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:723)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1094)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:723)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4562)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4454)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4383)
	at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:4328)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1329)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:959)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:302)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:162)
	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
	at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.Optional;

public class Error{
    public static void main(String[] args){
        Optional.of("23").map(str -> new Comparable<>(){
            public int compareTo(Integer o){
                return o;
            }
        });
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Don't use type inference


Comments
Verified with latest builds and this issue is reproducible in 9, 10 and 11. Looks like the issue is started appearing with the implementation of "JDK-8062373: Project Coin: diamond and anonymous classes", It is not a regression as JDK-8062373 is a new feature added in 9 ea b59 onwards. 9 GA - Fail 10 GA - Fail 11 ea b06 - Fail
02-04-2018