Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 402605 - Inline local variable creates multiple instances of the class
Summary: Inline local variable creates multiple instances of the class
Status: CLOSED DUPLICATE of bug 349276
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.8.1   Edit
Hardware: Macintosh Mac OS X
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-06 21:15 EST by Oleg Tsvinev CLA
Modified: 2013-03-07 13:14 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oleg Tsvinev CLA 2013-03-06 21:15:12 EST
Trying to inline variable cca in the following code works incorrectly as described.
Complete eclipse project is available here:
https://github.com/teosoft123/eclipse-inline-variable-refactoring-bug-demo.git

========= Details ===========

public class InlineBugDemo {

    String parameter;

    /**
     * Inline variable refactoring bug demo:
     * 1. Select variable cca
     * 2. Press Option+Command+I for "inline variable"
     * 3. The prompt dialog will show "Inline 2 occurences of local variable cca?"
     * 4. Hit "Enter" to proceed. Result will create two *instances* of the class CreateConnectionAsync as following:
     * 
     * new CreateConnectionAsync().execute(new String[] {parameter});
     * Connection<String> connection = new CreateConnectionAsync().get();
     * 
     */
    public void refactorMe() {
        CreateConnectionAsync cca = new CreateConnectionAsync();
        cca.execute(new String[] {parameter});
        Connection<String> connection = cca.get();
    }
Comment 1 Srikanth Sankaran CLA 2013-03-06 23:56:55 EST
Move to JDT/UI for comment.
Comment 2 Oleg Tsvinev CLA 2013-03-07 01:23:19 EST
Just tested it on Windows 8, eclipse 3.8.1, x64 JDK 1.6.0_16. Same problem. Don't see how to add other platforms to the same bug.
Comment 3 Stephan Herrmann CLA 2013-03-07 07:26:20 EST
Inlining a local variable always bears the risk of performing the side
effects of its initialization more than once.
1. how is your example different from any other scenario with 
   side effects in the local's initialization?
2. what do you expect the refactoring to produce?
Comment 4 Markus Keller CLA 2013-03-07 13:14:03 EST

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