skylot / jadx

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

[core][java-convert] Method decompilation failed - missing block/lost code #1318

Open nitram84 opened 2 years ago

nitram84 commented 2 years ago

This sample can't be decompiled with java-convert plugin. A missing block with lost code is reported. My test was made with openjdk8 and latest git version:

public class MissingBlockTest {
  private volatile boolean flag;

  public String test() {
    String result = "Hello";
    if (flag) {
      doSomething();
      if (!result.isEmpty()) {
        return result;
      }
    }

    if (flag) {
      doSomething();
    }
    return result;
  }

  private void doSomething() {
  }
}

Java-input plugin works fine. This sample can be used for unit tests.

skylot commented 2 years ago

@nitram84 thanks. This issue similar to code-duplication issues, here return should be duplicated to allow code restructure. Java-input plugin works fine because java bytecode keeps several return instructions, unlike dx, which merge all returns in one, so jadx trying to guess how to split them.