Bug 364220 - Compiler compliance: no error on leading comma for multivalued annotations
Summary: Compiler compliance: no error on leading comma for multivalued annotations
Status: VERIFIED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.8 M4   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-19 09:52 EST by Philippe Marschall CLA
Modified: 2011-12-05 10:21 EST (History)
3 users (show)

See Also:


Attachments
SampleAnnotation.java (69 bytes, text/plain)
2011-11-19 09:53 EST, Philippe Marschall CLA
no flags Details
SampleClass.java (62 bytes, text/plain)
2011-11-19 09:54 EST, Philippe Marschall CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Marschall CLA 2011-11-19 09:52:27 EST
The following code compiles with the Eclipse JDT compiler and the Oracle 1.7 compiler but fails with the Oracle 1.6 compiler.

@SampleAnnotation({"a", "b",})
public class SampleClass {

}

The problem is the trailing comma in the element value array initializer. Checking section 9.7 of the JLS [1] the production rule is

    ElementValueArrayInitializer:
        { ElementValuesopt ,opt }
        
which leads me to believe the code is legal and this is a compiler bug fixed in the Oracle 1.7 compiler.

This is a bit nasty because you can write code that compiles fine in Eclipse but will later fail to compile on the CI server that uses the Oracle compiler. If I read [2] correctly the compiler compliance setting is exactly intended for cases like this.

 [1] http://java.sun.com/docs/books/jls/third_edition/html/interfaces.html#9.7
 [2] http://eclipseandjazz.blogspot.com/2011/11/of-compliance-and-source-settings-in.html
Comment 1 Philippe Marschall CLA 2011-11-19 09:53:45 EST
Created attachment 207265 [details]
SampleAnnotation.java
Comment 2 Philippe Marschall CLA 2011-11-19 09:54:03 EST
Created attachment 207266 [details]
SampleClass.java
Comment 3 Ayushman Jain CLA 2011-11-20 12:37:06 EST
> If I read [2] correctly the compiler compliance setting is exactly intended for
> cases like this.

Yes, it is. Although we prefer to change compliance-wise setting when a behaviour changes for a newer version of java and we change eclipse compiler accordingly, so as to not break existing clients. In this case, we will have to buggify eclipse compiler to make it compatible to an old buggy javac behaviour. 
I do agree with your problem of cross-compiling though, and so I think it should be considered for a fix.

Srikanth, what do you think?
Comment 4 Srikanth Sankaran CLA 2011-11-20 22:05:23 EST
(In reply to comment #3)
> > If I read [2] correctly the compiler compliance setting is exactly intended for
> > cases like this.
> 
> Yes, it is. Although we prefer to change compliance-wise setting when a
> behaviour changes for a newer version of java and we change eclipse compiler
> accordingly, so as to not break existing clients. In this case, we will have to
> buggify eclipse compiler to make it compatible to an old buggy javac behaviour. 
> I do agree with your problem of cross-compiling though, and so I think it
> should be considered for a fix.
> 
> Srikanth, what do you think?

See also bug 112433 and all its numerous duplicates.

The compliance setting is meant to be used to match up with javac behavior
in areas where the spec was found in hindsight to be fuzzy, unclear, ill
specified, subject to interpretation to begin with etc and was later clarified.

It is not meant to be used to be bug compatible with javac. (See that even within a build stream say JDK6, javac behavior changes at various points, so
there is no way to be compliant with all JDK6 builds with a single control).

We don't want to introduce blatant bugs to be compatible with javac. Doubly
so it that would mean we would stop compiling code that we used to compile.
i.e the relaxing case at least is open for consideration, not the tightening
case.

Closing as WONTFIX.
Comment 5 Olivier Thomann CLA 2011-11-21 07:54:27 EST
If you have an issue with Oracle compiler, simply remove the trailing comma. I agree with the resolution.
Comment 6 Satyam Kandula CLA 2011-12-05 10:21:17 EST
Verified for 3.8M4 using build I20111202-0800