| Summary: | [compiler] syntax error hard to understand for annotation on static block | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Antonio Carvalho Junior <acdcjunior> |
| Component: | Core | Assignee: | ANIRBAN CHAKRABORTY <anchakrk> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | minor | ||
| Priority: | P3 | CC: | jarthana, markus.kell.r, srikanth_sankaran |
| Version: | 4.2.1 | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | stalebug | ||
It's strange that the compiler talks about "enum" when the code doesn't contain the "enum" keyword. Other than that, I'm not sure if we can come up with an error message that correctly identifies the user's intention. Java just doesn't allow annotations on blocks, and we can't have special cases for all possible kinds of source errors. I think a simple, as you said, "Annotations are not allowed on blocks" (or something alike) would suffice. This is syntax recovery's (DiagnoseParser) ugly underbelly showing up. We can easily handle this case, but as Markus said, we can't have special case handling for all forms of mangled programs. Common programming errors can be tracked in "error productions", I won't rate this as common. That being said, this could be a good self paced tutorial for a beginner in the team on how to change the grammar, generate the parser, handle invalid AST etc, I don't see an error production complicating the grammar much. Jay, please assign this to Shankha. We will take a call on whether to actually release it after we see the fix. If the special error production turns out to make stuff too complicated, another solution could be to reorder the productions, so that the error talks about ClassHeader instead of the less prevalent enum. Or we just leave it as is. (In reply to comment #5) > If the special error production turns out to make stuff too complicated, > another solution could be to reorder the productions, so that the error > talks about ClassHeader instead of the less prevalent enum. Or we just leave > it as is. And fix gazillion failing recovery related tests ? That sounds unappetizing :) Error productions are usually very clean, except that we need to restrict them to what we think are "likely" programming errors. The current candidate is not likely IMO, but still a good exercise for a learner. Hi Anirban, this would give a good overview of how to make changes to the grammar file, generate the parser and process the AST nodes. Please take a look. Some times making grammar changes causes issues in recovery. If this one doesn't cause any issues - we can consider the fix. Should Anirban find some time for this, we will reconsider this for 4.3. For now resetting the target. Hello. I think I found a variation of this bug, the error is similar, but this one seems to be a "more serious" bug. If I should open a new ticket, please let me know.
The code to reproduce is below. I use "Eclipse Java EE IDE for Web Developers. // Version: Juno Service Release 2 // Build id: 20130225-0426".
import java.util.List;
public class DescribeBug {
List<Object> os;
Object o;
public void method() {
// WORKS OK!
@SuppressWarnings("unchecked")
List<Object> osLOCAL = (List<Object>) o;
// Without the annotation, there is no error.
@SuppressWarnings("unchecked")
os = (List<Object>) o; // ERROR: os cannot be resolved to a type
// ERROR at the end of the annotation:
// Multiple markers at this line
// - Syntax error, insert "enum Identifier" to complete EnumHeaderName
// - Syntax error, insert "EnumBody" to complete BlockStatement
@SuppressWarnings("unchecked")
this.os = (List<Object>) o;
// Without the annotation, there is also no error.
// Please notice it is the SAME code as second assignment above, but the error is different
@SuppressWarnings("unchecked")
os = (List<Object>) o; // ERROR: Syntax error on token "os", VariableDeclaratorId expected after this token
}
}
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
Just create a file with the class below. The "static" word gets underlined in red and shows an error message that does not make sense. public class SupressAnnotationBug { @SuppressWarnings("unchecked") static { // the error says: Syntax error, insert "enum Identifier" to complete EnumHeader // do something... } }