United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7078543 Accepted syntax change b/w JDK 6 & 7 w/ -source 6: trailing ',' in ann value array
JDK-7078543 : Accepted syntax change b/w JDK 6 & 7 w/ -source 6: trailing ',' in ann value array

Details
Type:
Bug
Submit Date:
2011-08-12
Status:
Closed
Updated Date:
2011-12-02
Project Name:
JDK
Resolved Date:
2011-11-02
Component:
tools
OS:
linux
Sub-Component:
javac
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
6u30 (b10)

Related Reports
Relates:

Sub Tasks

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
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
EVALUATION

See comments.
                                     
2011-08-12



Hardware and Software, Engineered to Work Together