Enum comma being reported as an error

I have an enum such as {A.class, B.class,} // NOTE THE TRAILING COMMA

I have language level set to Java 5.0 for my project.

As far I've read the trailing comma is legal but IDEA is reporting it as an error.

Is this an inpsection I can change and if so which one?




On 3/3/2010 8:00 PM, Martin Zardecki wrote:

I have an enum such as {A.class, B.class,} // NOTE THE TRAILING COMMA

I doubt that.

You might have an enum such as:

enum MyEnum {A, B,}

Is that what you have? If not, please post the exact code that is
causing the error (or if you can't, then create a new code that does)


Very specifically the following gets reported as an error

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@SuiteClasses({         GenericTest.class,         OtherTest.class, // This last comma s/b legal and builds no problem in Eclipse

public class AllGenericTests {


Hi Martin,

  1. This is not enum but annotation array;
  2. JLS defines the following grammar for annotation array initializer -
            { ElementValuesopt ,opt }
  3. Moreover, there is a registered bug at Sun compiler - 6337964;

Conclusion: IDEA incorrectly highlights trailing comma at annotation array initializer as an error.

Please submit corresponding ticket about that to IDEA tracker.

Regards, Denis



I assigned it to responsible developer.


Please sign in to leave a comment.