Bug 393734

Summary: [extract method] A local remains uninitialized after initialization code is extracted to a method
Product: [Eclipse Project] JDT Reporter: Milos Gligoric <milos.gligoric>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r
Version: 4.2.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Milos Gligoric CLA 2012-11-06 19:00:51 EST
(Thanks to Yilong Li for helping to find this bug)

Steps to reproduce:
1. Invoke "Extract Method" on "(t = n()) == null" in code below
2. There is a compilation error in the resulting file.

class T {
}

public class ExtractMethodBug {

    void m() {
        T t;
        while ((t = n()) == null);
        run(t);
    }

    void run(T t) {
    }

    T n() {
        return null;
    }
}
Comment 1 Markus Keller CLA 2012-11-09 10:57:34 EST
The refactoring should find out that t is written in the extracted expression and that it is read afterwards in m(). Therefore, t should also be returned from the extracted method, which makes the return value ambiguous.
Comment 2 Eclipse Genie CLA 2020-06-21 00:55:58 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.

If you have further information on the current state of the bug, please add it. 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.
Comment 3 Eclipse Genie CLA 2022-07-05 17:12:07 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.

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