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

Wrong capture of a ?-extends wildcard with a ?-super wildcard as bound

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

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


      A DESCRIPTION OF THE PROBLEM :
      The capture conversion of a ?-extends wildcard that, via the class declaration and another parameter, has a ?-super wildcard as upper bound, is calculated wrong.
      This allows code with a type error to pass the compilers type checking.
      Example code attached.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile (and run) the example

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Error from the compiler
      ACTUAL -
      Compiles (and throws a ClassCastException)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // this code compiles without warnings, has no casts,
      // but throws a ClassCastException
      public class CaptureBug6b {
      public static void main(String[] args) {
      P<? super B, ? extends A> p = new P<A,A>(new A());
      B b = p.get();
      }
      }

      class P<U, T extends U> {
      P(T v) {t = v;}
      T t;
      T get() {return t;}
      }

      class A {}
      class B extends A {}

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                rmandalasunw Ranjith Mandala (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: