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

Creation of array of inner class of an enclosing wildcard type doesn't work

    Details

    • Subcomponent:
    • Resolved In Build:
      b03
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Verified

      Description

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

      java version "1.6.0-ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b40)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b40, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Currrent javac implementation doesn't permit
      in its parser to create an array of a inner class that have
      a generic enclosing class.

      see Foo example after :

      inner = new Foo<?>.Inner[10];
      or
      inner = new Foo<Object>.Inner[10];

      can't be parsed by the compiler.

      This problem come from comments on the Scott Violet weblog :
      (http://weblogs.java.net/blog/zixle/archive/2005/08/should_we_gener_1.html)
      and i don't see why it's not syntactically and semantically correct.

      Reading the JL3 grammar, it seems legal :
      new Foo<?>.Inner[10] is :
      'new'
      ClassOrInterfaceType
          (ClassOrInterfaceType(TypeName('Foo') TypeArguments('<?>')) '.'
      Identifier('Inner'))
      DimExprs('[10]')

      so it's syntactically legal.

      I think it semantically valid for the same reason that
      new List<?>[10] is valid.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile the Foo class.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      it compiles.
      ACTUAL -
      it doesn't compile.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      C:\eclipse\workspace\java-patch\src>javac Foo.java
      Foo.java:11: '(' or '[' expected
              inner = new Foo<?>.Inner[10];
                                ^
      1 error


      ---------- BEGIN SOURCE ----------
      public class Foo<T> {
          private T t;
          private Foo<?>.Inner[] inner;
          public Foo(T t) {
              this.t = t;
              inner = new Foo<?>.Inner[10];
          }
          private class Inner {
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      use a raw type instead :

      public class Foo<T> {
          private T t;
          private Foo<?>.Inner[] inner;
          public Foo(T t) {
              this.t = t;
              inner = new Foo.Inner[10];
          }
          private class Inner {
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ahe Peter Ahe
                Reporter:
                rmandalasunw Ranjith Mandala (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: