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

Bug 362509

Summary: [1.7] Improve AST recovery for TryStatement resource with missing type
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, deepakazad, srikanth_sankaran
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Bug Depends on:    
Bug Blocks: 362510    

Description Markus Keller CLA 2011-10-31 12:25:41 EDT
3.8 M3

Improve AST recovery for a TryStatement where the resource is missing a declared type. This is not a dup of bug 340837 (that one is about a complete absence of a TryStatement node).

    void foo() throws IOException {
        FileReader reader0 = new FileReader("file");
        writer0 = new FileWriter("out");

        try (FileReader reader = new FileReader("file");
                writer = new FileWriter("out")) {
            int ch;
            while ((ch = reader.read()) != -1) {
                System.out.println(ch);
            }
        }
    }

The 'writer = new FileWriter("out")' currently gets these errors on the second (incorrect) resource declaration:
- writer cannot be resolved to a type
- Syntax error on token "writer", VariableDeclaratorId expected after this

=> Would better be 'writer cannot be resolved to a variable', like for 'writer0'.

The AST would better also consider 'writer' as variable name and the type as missing.

Note: If I remove the type of 'FileReader reader' as well, then the recovery completely breaks down, and TryStatements has no resources any more.
Comment 1 Eclipse Genie CLA 2020-02-22 11:31:29 EST
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.