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

Empty array initializer with comma

    XMLWordPrintable

Details

    • hopper
    • generic
    • generic
    • Verified

    Description



      Name: boT120536 Date: 12/08/2000


      java version "1.3.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
      Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)


      Although it meets the grammar production listed in JLS 10.6, Javac does not
      compile this file:

      class test {
        int[] i = {,};
        int[] j = new int[] {,};
      }

      The errors reported are:

      test.java:2: illegal start of expression
          int[] j = {,};
                     ^
      test.java:3: illegal start of expression
          int[] i = new int[] {,};
                               ^
      2 errors


      The grammar states that an array initializer consists of the token left brace,
      the optional VariableInitializers (which I omitted), the optional comma (which I
      included), and the right brace. Therefore, both of these statements should
      generate zero-length arrays.

      If you decide instead that this is a spec bug, you should rewrite that
      production as:

      ArrayInitializer:
                    { VariableInitializersopt }
                    { VariableInitializers ,opt }

      in the style used in the main chapters, or else like you have done in Chapter 18
      (the BNF grammar of chapter 18 is sometimes easier to read, but I prefer coding
      the LALR(1) grammar scattered throughout the book, more like the first edition
      JLS):

      ArrayInitializer:
                    { [VariableInitializer {, VariableInitializer} [,]] }
      (Review ID: 113478)
      ======================================================================

      Attachments

        Activity

          People

            gafter Neal Gafter
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: