skylot / jadx

Dex to Java decompiler
Apache License 2.0
41.28k stars 4.84k forks source link

[core] Decompilation of loop failed #2 #1201

Open nitram84 opened 3 years ago

nitram84 commented 3 years ago

Hi,

in the following example the method "loopTest" can not be decompiled. I tested this class with latest git version fef3e21 and openjdk8. My example is already minimized and may be used for a unit test.

public class LoopTest2 {

  public void loopTest(int mode) {
    int val = 0;
    switch (mode) {
    case 1:
      for (;;) {
        val = getValue();

        if (val == -1 || val == 1) {
          doSomething();
          break;
        }

        if (checkValue(val)) {
          continue;
        }

        break;
      }
      doSomething();
      break;
    default:
      break;
    }
  }

  private int getValue() {
    return 0;
  }

  private boolean checkValue(int val) {
    return false;
  }

  private void doSomething() {
  }
}
nitram84 commented 3 years ago

Update: Form b5720bd to eedf32d the issue changed from bad blocks to behaviour change. In decompiled code the second invocation of doSomething() is also part of the loop. I would like to update my sample (different methods) without changing the cause:

public class LoopTest2 {

  public void loopTest(int mode) {
    int val = 0;
    switch (mode) {
    case 1:
      for (;;) {
        val = getValue();

        if (val == -1 || val == 1) {
          doSomething();
          break;
        }

        if (checkValue(val)) {
          continue;
        }

        break;
      }
      doSomething2();
      break;
    default:
      break;
    }
  }

  private int getValue() {
    return 0;
  }

  private boolean checkValue(int val) {
    return false;
  }

  private void doSomething() {
  }

  private void doSomething2() {
  }
}

In decompiled code doSomething2() is called inside and outside the loop.