Skip to content

[core] TernaryMod proceed when shouldn't #2844

@ewt45

Description

@ewt45

Issue details

The content of else if (i == 2) is replaced with ternary.
In TernaryMod, insn in else block (k = 0) is removed. However, this insn is also used in other places. In this case ternary shouldn't be processed.

Relevant log output or stacktrace

Provide sample and class/method full name

example code

public static void test(int i, int j) {
    int k;
    if (i == 1) {
        if (j == 2) {
            k = 3;
        } else {
            k = 0;
        }
    } else if (i == 2) {
        if (j == 3) {
            k = 4;
        } else {
            k = 0;
        }
    } else if (i == 3) {
        if (j == 4) {
            k = 5;
        } else {
            k = 0;
        }
    } else {
        k = 0;
    }
    System.out.println("k = " + k);
}

jadx decompile:

/* JADX WARN: Found duplicated region for block: B:6:0x0009  */
public static void test(int i, int i2) {
    int i3 = 3;
    if (i == 1) {
        if (i2 != 2) {
        }
    } else if (i == 2) {
        i3 = i2 == 3 ? 4 : 0;
    } else if (i == 3 && i2 == 4) {
        i3 = 5;
    }
    System.out.println("k = " + i3);
}

Jadx version

latest commit (7ce40ba)

Metadata

Metadata

Assignees

Labels

CoreIssues in jadx-core modulebug

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions