Bug 578121

Summary: [Code Clean-Up] "Pull down common code from if/else statement" results into compilation failure
Product: [Eclipse Project] JDT Reporter: Nicolas Baumann <nicolas.baumann1>
Component: UIAssignee: Fabrice Tiercelin <fabrice.tiercelin>
Status: ASSIGNED --- QA Contact:
Severity: normal    
Priority: P3 CC: fabrice.tiercelin
Version: 4.22   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Nicolas Baumann CLA 2022-01-09 05:50:58 EST
When I choose Source->Clean-Up "Pull down common code from if/else statement" on the example below, it results into a compilation failure.

Example:

public class Test {
    private static final int ERROR_ACTION = 0;
    private static final int ACCEPT_ACTION = 1;
    private static final int NUM_RULES = 2;

    public String reduce(int act) {
        String reduceName = "";
        if (act <= NUM_RULES) {
            act--;
        } else if (act > ERROR_ACTION) {
            return reduceName;
        } else {
            if (act < ACCEPT_ACTION) {
                return reduceName;
            }
            return reduceName;
        }
        return reduceName;
    }
}


Result:

public class Test {
    private static final int ERROR_ACTION = 0;
    private static final int ACCEPT_ACTION = 1;
    private static final int NUM_RULES = 2;

    public String reduce(int act) {
        String reduceName = "";
        if (act <= NUM_RULES) {
            act--;
        } else {
            if () {
            }
            return reduceName;
        }
        return reduceName;
    }
}

The empty expression inside the if causes the compilation error.

The example is simplified from the orginal code of org.eclipse.jdt.internal.codeassist.complete.CompletionParser.reduce(int)
Comment 1 Nicolas Baumann CLA 2022-01-09 05:51:35 EST
Version: 2021-12 (4.22.0)
Build id: 20211202-1639
Comment 2 Nicolas Baumann CLA 2022-01-13 02:59:43 EST
See also this similar bug, already resolved
https://github.com/JnRouvignac/AutoRefactor/issues/487
Comment 3 Eclipse Genie CLA 2024-01-04 06:33:53 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.

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.