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

Compiler error when using F-bounded generics with free type variables

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 6
    • tools
    • b48
    • x86
    • linux
    • Verified

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
      javac 1.6.0


      ADDITIONAL OS VERSION INFORMATION :
      Linux toth 2.6.15-52-386 #1 PREEMPT Mon Jun 9 17:24:46 UTC 2008 i686 GNU/Linux
      a

      A DESCRIPTION OF THE PROBLEM :
      Running javac on the attached program causes a type error. It appears to be caused by the occurrence of "U" in the generic declaration "<B extends Bar<U,B>>" being treated as a binding occurrence rather than as a free occurrence, thus causing the unification of V with itself in "x.<Y>bar(y)" to fail. If U and V are removed, the problem goes away. If the upper bound on B is removed, the problem goes away.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac the attached code, note type error.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Successful compilation.
      ACTUAL -
      Type error.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Test.java:5: <B>bar(Bar<V,B>) in Bar<V,X> cannot be applied to <Y>(Bar<V,Y>)
          void foo() { x.<Y>bar(y); }
                        ^


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class Foo<V,X extends Bar<V,X>,Y extends Bar<V,Y>> {

          Bar<V,X> x;
          Bar<V,Y> y;
          void foo() { x.<Y>bar(y); }

      }

      interface Bar<U,A> {
          <B extends Bar<U,B>> void bar(Bar<U,B> x);
      }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The version of javac distributed with eclipse does not appear to have this bug.

            mcimadamore Maurizio Cimadamore
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: