Bug 578121 - [Code Clean-Up] "Pull down common code from if/else statement" results into compilation failure
Summary: [Code Clean-Up] "Pull down common code from if/else statement" results into c...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.22   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Fabrice Tiercelin CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-09 05:50 EST by Nicolas Baumann CLA
Modified: 2024-01-04 06:33 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 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.