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

Accepted syntax change b/w JDK 6 & 7 w/ -source 6: trailing ',' in ann value array

    Details

    • Subcomponent:
    • Resolved In Build:
      b10
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Verified

      Description

      Given the following source file:

      ---%<---
      class Demo {
          @interface A {
              int[] value();
          }
          @A({
              1,
              2,
              3,
          })
          static class C {}
      }
      ---%<---

      JDK 6 javac rejects it:

      ---%<---
      $ .../jdk6/bin/javac -J-showversion -source 6 Demo.java
      java version "1.6.0_26"
      Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
      Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)

      Demo.java:9: illegal start of expression
          })
          ^
      1 error
      ---%<---

      while JDK 7 javac accepts it:

      ---%<---
      $ .../jdk7/bin/javac -J-showversion -source 6 -Xlint:-options Demo.java
      java version "1.7.0"
      Java(TM) SE Runtime Environment (build 1.7.0-b147)
      Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)

      ---%<---

      With a given source level (here 6), either this syntax should be forbidden by all supported versions of javac, or accepted by all supported versions. If it is intentional that this be newly permitted, that should be limited to -source 7, or a fix backported to a JDK 6 update.

      Otherwise it is impossible to freely substitute newer versions of javac to take advantage of bug fixes and the like, since there is a risk of inadvertently using a construct rejected by an older version of the compiler (to say nothing of ecj and the like).

      Affects users of the NetBeans IDE: since the IDE's Java editor embeds JDK 7 javac, this source file is marked as free of errors in the editor, though an Ant build (for example) using JDK 6 fails.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dmeetry Dmeetry Degrave (Inactive)
                Reporter:
                jglick Jesse Glick (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: