Bug 432539 - [parser][ast rewrite] Fake 'finally' block from recovery causes problems in rewrite
Summary: [parser][ast rewrite] Fake 'finally' block from recovery causes problems in r...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Manoj N Palat CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 338785
  Show dependency tree
 
Reported: 2014-04-10 12:50 EDT by Markus Keller CLA
Modified: 2020-04-24 20:34 EDT (History)
6 users (show)

See Also:


Attachments
Workaround in ASTRewriteAnalyzer (1.92 KB, patch)
2014-04-10 12:50 EDT, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2014-04-10 12:50:08 EDT
Created attachment 241849 [details]
Workaround in ASTRewriteAnalyzer

For this example from bug 338785 comment 0, the parser inserts a fake 'finally' block: 

import java.io.File;

public class CLAZZ {

	public void method() {
		try { //press Ctrl + 1 on try to view quickfix, you can remove try block but can not add finally
			File f = new File("c:\testfile");
			f.createNewFile(); // throws IOException, which means I want/have to add finally block
		} // Error is on this line
	}
}

Is the fake node really necessary? I wonder if bug 143001 would not better be implemented by changing line
TryStatement ::= 'try' TryBlock Catches
in java.g to
TryStatement ::= 'try' TryBlock CatchesOpt
and then reporting the syntax error manually when the TryStatement is missing catch and finally.

The fake 'finally' block is problematic for ASTRewrite, since it assumes the 'finally' keyword is already there in source. When we try to set a real 'finally' block, then the keyword is still missing.

If the better recovery suggested above doesn't work out, then a workaround could be to fix the problem in ASTRewriteAnalyzer, see attached patch.
Comment 1 Markus Keller CLA 2014-07-15 08:04:33 EDT
This blocks bug 338785. Would be good to have a fix early in Mars, so that we have more time to find regressions that may arise from the grammar change (and avoid trouble like bug 430336).
Comment 2 Jay Arthanareeswaran CLA 2014-07-15 09:17:03 EDT
Manoj, please take a look. Please check with Srikanth on feasibility of the grammar change.
Comment 3 Manoj N Palat CLA 2014-12-07 22:16:59 EST
Sasi: Could you please comment on the grammar change?
Comment 4 Sasikanth Bharadwaj CLA 2015-01-05 01:55:12 EST
(In reply to comment #3)
> Sasi: Could you please comment on the grammar change?
I can confirm that the suggested grammar change works. Yet to look at the reporting syntax error later part.
Comment 5 Manoj N Palat CLA 2015-04-07 03:03:50 EDT
This got missed out in the early Mars releases. Wouldn't want a grammar change at this stage[see comment 1 as well]. Will aim for early 4.6.
Comment 6 Manoj N Palat CLA 2016-04-05 01:02:57 EDT
To be targetted for 4.7M1
Comment 7 Manoj N Palat CLA 2017-05-25 00:00:36 EDT
Moving out to early 4.8
Comment 8 Eclipse Genie CLA 2020-04-24 20:34:37 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.