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

assignment to array-lower bounded wildcard

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P5
    • Resolution: Duplicate
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_07"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux meco 2.6.10 #1 SMP Wed Aug 31 19:48:13 CEST 2005 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      The following assignment to a lower bounded wildcard should compile without errors as the array is assignable to the wildcard capture's lower bound. Instead, javac produces the below compiler error.

      Note that javac 1.6 does this correctly! However, if there still are release cycles for javac 1.5, it would be nice to also fix it there.

      === $ cat -n Bug1.java
           1 public class Bug1<T> {
           2 T t;
           3
           4 void foo() {
           5 Bug1<? super Integer[]> a = null;
           6 a.t = new Integer[0];
           7 }
           8 }

      === $ javac Bug1.java
        Bug1.java:6: incompatible types
      found : java.lang.Integer[]
      required: capture of ? super java.lang.Integer[]
                      a.t = new Integer[0];
                            ^
      1 error

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the provided source file.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No compiler errors should be generated.
      ACTUAL -
      The assignment produces a compiler error.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Bug1.java:6: incompatible types
      found : java.lang.Integer[]
      required: capture of ? super java.lang.Integer[]
                      a.t = new Integer[0];
                            ^
      1 error

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Bug1<T> {
      T t;

      void foo() {
      Bug1<? super Integer[]> a = null;
      a.t = new Integer[0];
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Use javac 1.6.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ahe Peter Ahe
                Reporter:
                ndcosta Nelson Dcosta
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: