JDK-7078543 : Accepted syntax change b/w JDK 6 & 7 w/ -source 6: trailing ',' in ann value array
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2011-08-12
  • Updated: 2011-12-02
  • Resolved: 2011-11-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 6
6u30 b10Fixed
Related Reports
Relates :  
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.

Comments
EVALUATION See comments.
2011-08-12

WORK AROUND Be careful to never use a trailing comma in arrays in annotation values (unlike other array initializer expressions where they are permitted). Verify by using JDK 6 javac.
2011-08-12