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

Java compiler - generics nested type declaration compilation failure

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 8u11
    • tools
    • x86
    • linux_redhat_6.0

      FULL PRODUCT 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)

      ADDITIONAL OS VERSION INFORMATION :
      CentOS release 6.5 (Final)

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      javac 1.8.0_20


      A DESCRIPTION OF THE PROBLEM :
      Create Test.java with following code


      interface Iface<T1> {}

      class Impl implements Iface<Impl> {}

      class Acceptor<T2 extends Iface<T2>> {
          public Acceptor(T2 obj) {}
      }

      public class Test {
          public static void main(String[] args) {
              Acceptor<?> acceptor = new Acceptor<>(new Impl());
          }
      }



      try to compile it

      javac Test.java
      Test.java:12: error: incompatible types: cannot infer type arguments for Acceptor<>
              Acceptor<?> acceptor = new Acceptor<>(new Impl());
                                                 ^
          reason: inference variable T2 has incompatible bounds
            equality constraints: Impl
            upper bounds: Iface<CAP#1>,Iface<T2>
        where T2 is a type-variable:
          T2 extends Iface<T2> declared in class Acceptor
        where CAP#1 is a fresh type-variable:
          CAP#1 extends Iface<CAP#1> from capture of ?
      1 error



      http://stackoverflow.com/questions/23063474/why-does-this-java-8-program-not-compile
      https://bugs.openjdk.java.net/browse/JDK-8043926



      REGRESSION. Last worked in version 8u11

      ADDITIONAL REGRESSION INFORMATION:
      release 1.8.0_20 isn't available in regression so marking it 11 it is there in 5, 11, 20 all minor releases for 1.8


      REPRODUCIBILITY :
      This bug can be reproduced always.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: