Community
Participate
Working Groups
Define this class: public abstract class Agent { public abstract String talk(); public abstract listen(String message); } When compiled, two errors show up. Against the talk() method, it says "Abstract methods do not specify a body." Against the listen() method, it says "Syntax error on token ";", "{" expected." The first error message is wrong, because there is no problem with the definition of the talk method. On the second method, it seems to interpret the abstract keyword as the return type, and then complains that there is no method body. Shouldn't it be able to detect and report that the return type is missing?
The only parsing rules which can digest a missing return type method is a constructor one, which cannot be abstract and thus expects a block body (not a semi-colon one). This explains the parse error (we could investigate improving this). The first error though is more embarrassing.
First reported error is due to the fact our syntax recovery did not position the bit for semi-colon body method, thus fooling the method check later on. This one is fixed. Now I obtain the following 2 errors: ---------- 1. ERROR in d:\Agent.java (at line 7) public abstract listen(String message); ^^^^^^^^^^^^^^^^^^^^^^ Return type for the method is missing ---------- 2. ERROR in d:\Agent.java (at line 7) public abstract listen(String message); ^ Syntax error on token ";", "{" expected ---------- I agree that the second one isn't very helpful, but the proper diagnosis is on the number one (and the second could be discared with a parser change: tolerate constructor with semi-colon body). I think this latter change is interesting anyway, since it will improve our behavior for recovery in general. Olivier - can you please investigate if this grammar change is breaking anything (still no ambiguity as I would expect).
Regression test added (NegativeTests.test253), will need to be tuned after complete fix (with grammar change).
The second error is gone after changing the grammar to consume silently the constructor without a body. See consumeInvalidConstructorDeclaration on the Parser. Released in HEAD. All tests are green and the NegativeTests.test253 has been updated to remove the second error.
*** Bug 8789 has been marked as a duplicate of this bug. ***