skylot / jadx

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

[core] Undefined variable after decompiling #1307

Open nitram84 opened 2 years ago

nitram84 commented 2 years ago

I tried to decompile this class (compiled with openjdk8)

public class UndefinedVariableTest {

  public final int parseCharArray(final char[] s) {
    int i;
    for (i = 0; i < s.length; i++) {
      final char c = s[i];
      if (c != 'a' && c != 'b') {
        break;
      }
    }
    return i;
  }
}

This is the result with latest git version

public class UndefinedVariableTest {
    public final int parseCharArray(char[] s) {
        int i = 0;
        while (i < s.length && ((c = s[i]) == 'a' || c == 'b')) {
            i++;
        }
        return i;
    }
}

Variable c is undefined. Using the gui "c" can be renamed to "s" producing a name collision. Same result with java-input and java-convert.

skylot commented 2 years ago

@nitram84 I fixed undefined variable issue. But these inlinings is too aggressive and looks like an issue, I will try to fix it also.