Bug 217851 - [extract local] doesn't correctly extract variables from a loop
Summary: [extract local] doesn't correctly extract variables from a loop
Status: RESOLVED DUPLICATE of bug 27740
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   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: 2008-02-05 11:10 EST by einarpeak CLA
Modified: 2008-02-06 03:40 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description einarpeak CLA 2008-02-05 11:10:09 EST
Consider the following (correct) sample code:

    static class Node {
        private Node parent;
        public Node getParent() {
            return parent;
        }
    }

    Node getAncestor(Node node) {
        while (node.getParent() != null && node.getParent().getParent() != null) {
            node = node.getParent();
        }
        return node;
    }

Now try to use Eclipse refactoring option "extract local variable" for "node.getParent()" and you will get this incorrect code:

    Node getAncestor(Node node) {
        Node parent = node.getParent();
        while (parent != null && parent.getParent() != null) {
            node = parent;
        }
        return node;
    }

This bug was observed on "EasyEclipse Server Java" version 1.2.1, which is based on Eclipse build id M20060921-0945, although there's no way to know what's the exact corresponding official Eclipse version.
Comment 1 Jerome Lanneluc CLA 2008-02-05 11:13:52 EST
Moving to JDT/UI
Comment 2 Martin Aeschlimann CLA 2008-02-06 03:40:23 EST

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