JDK-8132535 : Compiler fails with diamond anonymous class creation with intersection bound of enclosing class
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2015-07-29
  • Updated: 2018-04-20
  • Resolved: 2015-10-01
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 b85Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
The following test cause compiler to fail.
Here qualified anonymous class instance creation expression with diamond is used.
Bound of enclosing class type parameter need to be intersection.

Minimal test case:

interface I {}
class C {}
class B extends C implements I {}

class Test <T extends C & I>{
    class A <T>{
        public A(T b) {
        }
    }
    public void foo(){
        A a = new Test<>().new A<>(new B()){} ;
    }
}

It was tested with jdk 9b68 and 9b74

The failing JCK tests are:
lang/EXPR/expr629/expr62902m201111/expr62902m201111.html
Comments
See JDK-8155701 for a duplicate, which has been reopened on the grounds that the issue has not been fixed.
20-04-2018

@Dan, I grabbed this one. Hope that is fine.
14-09-2015

Caused by a call to getTypeArguments() instead of allParams() in the denotable checker.
30-07-2015

Since the supertype of the anonymous class is 'Test<Serializable&Cloneable>.A<Object>', this seems to be a clear case of violating the spec (JDK-8073593): the supertype mentions an intersection type, so the anonymous class should be rejected.
29-07-2015

Even more minimal example: static class Test <T extends java.io.Serializable & Cloneable>{ class A <X>{} public void foo(){ new Test<>().new A<>(){} ; } } All that matters is that the diamond anonymous class has a superclass enclosing instance whose type is an intersection.
29-07-2015

"causes compiler to fail" means "causes an AssertionError": java.lang.AssertionError: Unexpected intersection type: JDK8132535.C&JDK8132535.I at com.sun.tools.javac.jvm.ClassWriter.enterInner(ClassWriter.java:966) at com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.classReference(ClassWriter.java:318) at com.sun.tools.javac.code.Types$SignatureGenerator.assembleClassSig(Types.java:4734) at com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:4666) at com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:297) at com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:4777) at com.sun.tools.javac.code.Types$SignatureGenerator.assembleClassSig(Types.java:4753) at com.sun.tools.javac.code.Types$SignatureGenerator.assembleClassSig(Types.java:4740) at com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:4666) at com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:297) at com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1677) at com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1593) at com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:716) at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1538) at com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1502) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:871) at com.sun.tools.javac.main.Main.compile(Main.java:254) at com.sun.tools.javac.main.Main.compile(Main.java:142) at com.sun.tools.javac.Main.compile(Main.java:56) at com.sun.tools.javac.Main.main(Main.java:42)
29-07-2015