Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 374083 - [quick assist][clean up] Remove unused local variables-save action, causes syntax error
Summary: [quick assist][clean up] Remove unused local variables-save action, causes sy...
Status: CLOSED DUPLICATE of bug 251471
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-13 10:50 EDT by dvice null CLA
Modified: 2012-04-09 08:04 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dvice null CLA 2012-03-13 10:50:26 EDT
Build Identifier: Version: Indigo Service Release 2 Build id: 20120216-1857

Here is a sample code: 

public class Remove
{
    public void foo()
    {
        byte value;
        value = (byte) getInt();
    }
    
    long getInt()
    {
        return 2;
    }
}

I have turned on settings in Window -> Preferences -> Java -> Editor -> Save Actions -> Additional Actions[x] -> Configure -> Unnecessary Code -> Remove unused local variables [x]. 

And when I save the file, it generates code like this, where I get syntax error on line that has "(byte) getInt();". 

public class Remove
{
    public void foo()
    {
        (byte) getInt();
    }
    
    long getInt()
    {
        return 2;
    }
}

Note that writing the code like this:
byte value = (byte) getInt();

Generates output that compiles.

Reproducible: Always

Steps to Reproduce:
Steps can be found from the Details.
Comment 1 Ayushman Jain CLA 2012-03-13 15:47:15 EDT
Moving to JDT/UI
Comment 2 Deepak Azad CLA 2012-04-09 08:04:50 EDT

*** This bug has been marked as a duplicate of bug 251471 ***