Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core][D8] Multi-variable type inference failed for types: [boolean, int] #1943

Open
nitram84 opened this issue Jul 7, 2023 · 1 comment
Assignees
Labels
bug Core Issues in jadx-core module type-inference
Milestone

Comments

@nitram84
Copy link
Contributor

nitram84 commented Jul 7, 2023

A multi-variable type inference can be observed when this class is decompiled with lastest git (compiled with openjdk8, decompiled with "use dx/d8" and option "d8"). This class is a minimized extract. The original class didn't have any useless variables or dead stores.

import java.util.List;

public class MultiVariableTypeInferenceFailed {

  public void doSomething() {
    Object o1 = null;
    List<String> stringList = this.getStrings();
    int num = 0;
    Object o2 = null;
    boolean cond = false;
    for (String curString : stringList) {
      String s0 = curString;
      Object o3 = getObject(0);
      for (int i = 1; i < 42; i++) {
   	    String s1 = "jadx";
        String s2 = "is great!";
        getObject(0);
        setFlag(false);
        String s3 = s0;
        for (String s : getStrings()) {
          write(s);
        }
      }
    }
  }

  private List<String> getStrings() {
    return null;
  }

  private void write(String s) {
  }

  private void setFlag(boolean b) {
  }

  private Object getObject(int i) {
    return null;
  }
}

Decompiled result is:

import java.util.List;

/* loaded from: classes.dex */
public class MultiVariableTypeInferenceFailed {
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r9v0 */
    /* JADX WARN: Type inference failed for: r9v1, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r9v2 */
    public void doSomething() {
        List<String> stringList = getStrings();
        for (String str : stringList) {
            ?? r9 = 0;
            getObject(0);
            int i = 1;
            while (i < 42) {
                getObject(r9);
                setFlag(r9);
                for (String s : getStrings()) {
                    write(s);
                }
                i++;
                r9 = 0;
            }
        }
    }

    private List<String> getStrings() {
        return null;
    }

    private void write(String s) {
    }

    private void setFlag(boolean b2) {
    }

    private Object getObject(int i) {
        return null;
    }
}
@nitram84 nitram84 added bug Core Issues in jadx-core module labels Jul 7, 2023
@skylot
Copy link
Owner

skylot commented Jul 8, 2023

@nitram84 thanks, this case is weird 🤣
There are 2 ways for fix:

  1. Check if variable value not changes in loop and inline it (correct types will be used)
  2. Apply in place int to boolean conversion, similar to this case: [core] Miss of casts among primitive types #921 (comment)

Actually, second should be implemented anyway, and first can be a little tricky.

@skylot skylot added this to the TBD milestone Jul 8, 2023
@skylot skylot self-assigned this Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Issues in jadx-core module type-inference
Projects
None yet
Development

No branches or pull requests

2 participants