Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 362031

Summary: Typo: Finally -> finally (and two other minor tweaks)
Product: [Eclipse Project] JDT Reporter: Dani Megert <daniel_megert>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: trivial    
Priority: P3 CC: amj87.iitr, noopur_gupta, srikanth_sankaran, stephan.herrmann
Version: 3.3   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Dani Megert CLA 2011-10-26 03:31:25 EDT
Very old bug.

Paste this into Package Explorer:
	void bug() {
		try {
			
		}
	}

==> error says:
Syntax error, insert "Finally" to complete BlockStatements

should be:
Syntax error, insert 'finally' to complete block statements
Comment 1 Ayushman Jain CLA 2011-10-27 02:49:08 EDT
Dani, this is actually a parser error, which happens when parser cannot complete to any rule, and goes into recovery to fetch the closest match. In this example, to reach the closest match the user has to insert

finally {
}

which is given by the rule Finally ::= 'finally' Block

Doing so will satisfy the parent rule BlockStatements.

The error message picks up the rules from the parser and thats why you see "Finally" and "BlockStataments"

This happens in all parse errors, such as for WhileStatement, ForStatement, etc.
Comment 2 Ayushman Jain CLA 2011-10-27 02:50:14 EDT
(In reply to comment #1)
> The error message picks up the rules from the parser 

I meant from the grammar file java.g
Comment 3 Dani Megert CLA 2011-10-27 02:52:37 EDT
I'm not sure what you try to sell me ;-). The error messages should target a normal user and not require AST knowledge. Clearly, inserting "Finally" is not a good hint since that won't ever compile.
Comment 4 Ayushman Jain CLA 2011-10-27 06:37:45 EDT
(In reply to comment #3)
> I'm not sure what you try to sell me ;-)

Well i was just offering an explanation of why you see what you see, and that this is just expected behaviour and not a "typo" ;)
Srikanth, what do you think about this?
Comment 5 Dani Megert CLA 2011-10-27 06:47:17 EDT
> this is just expected behaviour and not a "typo" ;)
Mmmh, no - it is the *implemented* behavior ;-)
Comment 6 Stephan Herrmann CLA 2011-10-27 07:16:18 EDT
(In reply to comment #5)
> > this is just expected behaviour and not a "typo" ;)
> Mmmh, no - it is the *implemented* behavior ;-)

Apparently, developers and users expect different behavior :)

The error is emitted by a part of the compiler that we have only limited
control over, because everything works from tables generated by the
parser generator.

I see two things we could change:

The readableName of the rule mentioned by Ayush could be changed to s.t.
like "FinallyBlock" to be more consistent with other rules and to indicate
that we're not talking about a keyword ("Finally") but more abstractly
about a syntax element.

Second, I'm not very happy with the quotes in the error message, because
these imply that something should be inserted verbatim, which is not the
case for any of these message.
Comment 7 Dani Megert CLA 2011-10-27 07:29:02 EDT
This is what javac 1.7 says:

Snippet.java:5: error: 'try' without 'catch', 'finally' or resource declarations

            try {
            ^
1 error

==> they show messages that refer to source elements and not internal AST nodes.


> Second, I'm not very happy with the quotes in the error message, because
> these imply that something should be inserted verbatim
Exactly.
Comment 8 Stephan Herrmann CLA 2011-10-27 08:07:58 EDT
(In reply to comment #7)
> ==> they show messages that refer to source elements and not internal AST
> nodes.

At a closer look "Finally" isn't even an invention of the JDT team,
but directly taken from the JLS:

TryStatement:
        try Block Catches
        try Block Catchesopt Finally

Catches:
        CatchClause
        Catches CatchClause

CatchClause:
        catch ( FormalParameter ) Block

Finally:
        finally Block

This is our specification and that's what the error messages refer to.

I agree that users could get better help in these messages, but the current
state doesn't look like an accident but like a well-considered strategy.

Changing anything here in a consistent way will be a major change.
Comment 9 Dani Megert CLA 2011-10-27 08:36:30 EDT
> At a closer look "Finally" isn't even an invention of the JDT team,
> but directly taken from the JLS:
Yes, 'Finally' is part of the JSL but how the message is crafted together is an invention of the JDT team ;-)

Maybe we could resolve the Finally as indicated in the JLS i.e.

Syntax error, insert "Finally" to complete BlockStatements
resolve "Finally"
==>
Syntax error, insert 'finally' Block to complete BlockStatements


> Changing anything here in a consistent way will be a major change.
In that case I wouldn't touch it, except for removing the double quotes. We shouldn't spend a days on this.
Comment 10 Srikanth Sankaran CLA 2011-10-27 12:45:55 EDT
(In reply to comment #7)
> This is what javac 1.7 says:
> 
> Snippet.java:5: error: 'try' without 'catch', 'finally' or resource
> declarations

I think it should be possible to augment the grammar with some error 
productions so that it doesn't trigger recovery due to parser error,
but we accept the malformed construct and diagnose it precisely. That said,

(In reply to comment #8)

> Changing anything here in a consistent way will be a major change.

I am afraid so.
Comment 11 Eclipse Genie CLA 2019-08-29 19:58:31 EDT
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.