Bug in Annotation Processing (Java 6 Update 12 / Eclipse)


Just uncovered a fun bug in one of the Java Compiler / Eclipse (haven’t checked to see which one is behaving exactly correctly).

If you are working Eclipse then the Eclipse compiler believes the following snippet of code is OK:

@org.hibernate.annotations.Table(
  appliesTo = "PendingVotes",
  indexes = {
    @Index(name = "VoteId", columnNames = { "VoteId" }),
  })

However, the Java compiler (Version 6, update 12) will report the following error:

annotation.java:6: illegal start of expression
})
^

Now, I’ll display that snippet again and highlight the problem:

@org.hibernate.annotations.Table(
  appliesTo = "PendingVotes",
  indexes = {
    @Index(name = "VoteId", columnNames = { "VoteId" }),
  })

See that sneaky little comma at the end? I believe this is valid syntax (it allows someone to add another item later and only alter a single line – useful for generating diffs).

Remove that comma and everything becomes pain free again.

Advertisements

One Response to Bug in Annotation Processing (Java 6 Update 12 / Eclipse)

  1. Brian says:

    thanks for that tip been going crazy trying to fix the same issue

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: