Syntax error , insert "EnumBody" to complete EnumDeclaration

Mukul Goel picture Mukul Goel · Nov 1, 2012 · Viewed 35k times · Source

I was in middle of coding and accidentally put the following line of code at the part of class where we declare instance variables. but i checked and it gives the same error anywhere by anywhere i mean : inside a static block, inside constructor, inside any class method. except when private; is put as the first line of the class it gives Syntax error, insert "EnumBody" to complete ClassBodyDeclarations (as written by @chaitanya10 in comments below and also verified by me on my workspace) error in eclipse tooltip when we hover cursor over it.

I understand there is error.
but I dont understand the error message when i hover cursor over the error. what is the meaning of this message?

why does it expecting EnumBody ?

Below is the screenshot.

enter image description here

Answer

Stephen C picture Stephen C · Nov 8, 2012

For a real explanation, someone would need to do a detailed analysis of the syntax checking, and the syntax error recovery and reporting components of the Eclipse Java compiler front end. But the most likely explanation is that your "unusual" syntax error has "confused" the compiler's syntax error recovery code.

In short it is a minor compiler bug (or feature).

It is possible that the developers know about this, but have refrained from fixing it because of one or more of the following:

  • It doesn't happen often enough to be prioritized.
  • It might be hard to do a better job without affecting other error recovery cases.
  • Any change could break1 a number of compiler error regression tests.
  • There are other higher priority issues to deal with.

1 - Break ... in the sense of causing tests to fail because of assumptions in the test rather than problems in the code being tested. Fixing these regressions could be burdensome.