diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeInferenceVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeInferenceVisitor.java index 89031707aee8d954b448b4b5fbef851d041d6782..37fc056055bab287228f592eece699e2a32fac1f 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeInferenceVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/typeinference/TypeInferenceVisitor.java @@ -913,25 +913,20 @@ public final class TypeInferenceVisitor extends AbstractVisitor { } boolean fixed = false; - for (ITypeBound bound : typeInfo.getBounds()) { - if (bound.getBound() == BoundEnum.USE - && fixBooleanUsage(mth, bound)) { + for (RegisterArg arg : new ArrayList<>(var.getUseList())) { + if (fixBooleanUsage(mth, arg)) { fixed = true; } } return fixed; } - private boolean fixBooleanUsage(MethodNode mth, ITypeBound bound) { - ArgType boundType = bound.getType(); + private boolean fixBooleanUsage(MethodNode mth, RegisterArg boundArg) { + ArgType boundType = boundArg.getInitType(); if (boundType == ArgType.BOOLEAN || (boundType.isTypeKnown() && !boundType.isPrimitive())) { return false; } - RegisterArg boundArg = bound.getArg(); - if (boundArg == null) { - return false; - } InsnNode insn = boundArg.getParentInsn(); if (insn == null || insn.getType() == InsnType.IF) { return false; diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBooleanToInt.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBooleanToInt.java index 440f6e246b585971437c8702a1941f87f05cb459..ae0b6326b2048ba22b5d8d2b5d867fa3b1570f5b 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBooleanToInt.java +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBooleanToInt.java @@ -6,6 +6,7 @@ import jadx.tests.api.SmaliTest; import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; +@SuppressWarnings("CommentedOutCode") public class TestBooleanToInt extends SmaliTest { // @formatter:off diff --git a/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBooleanToInt2.java b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBooleanToInt2.java new file mode 100644 index 0000000000000000000000000000000000000000..96d6c94f013eed8c86f1fba589c42c02d596b67b --- /dev/null +++ b/jadx-core/src/test/java/jadx/tests/integration/conditions/TestBooleanToInt2.java @@ -0,0 +1,40 @@ +package jadx.tests.integration.conditions; + +import org.junit.jupiter.api.Test; + +import jadx.tests.api.SmaliTest; + +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; + +@SuppressWarnings("CommentedOutCode") +public class TestBooleanToInt2 extends SmaliTest { + + // @formatter:off + /* + public static class TestCls { + public void test() { + boolean v = getValue(); + use1(Integer.valueOf(v)); + use2(v); + } + + private boolean getValue() { + return false; + } + + private void use1(Integer v) { + } + + private void use2(int v) { + } + } + */ + // @formatter:on + @Test + public void test() { + assertThat(getClassNodeFromSmali()) + .code() + .containsOne("use1(Integer.valueOf(value ? 1 : 0));") + .containsOne("use2(value ? 1 : 0);"); + } +} diff --git a/jadx-core/src/test/smali/conditions/TestBooleanToInt2.smali b/jadx-core/src/test/smali/conditions/TestBooleanToInt2.smali new file mode 100644 index 0000000000000000000000000000000000000000..88db44dc102e71dad5dd1ed629e65665a51b8e9c --- /dev/null +++ b/jadx-core/src/test/smali/conditions/TestBooleanToInt2.smali @@ -0,0 +1,29 @@ +.class public Lconditions/TestBooleanToInt2; +.super Ljava/lang/Object; + +.method public test()V + .registers 3 + invoke-direct {p0}, Lconditions/TestBooleanToInt2;->getValue()Z + move-result v0 + invoke-static {v0}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer; + move-result-object v1 + invoke-direct {p0, v1}, Lconditions/TestBooleanToInt2;->use1(Ljava/lang/Integer;)V + invoke-direct {p0, v0}, Lconditions/TestBooleanToInt2;->use2(I)V + return-void +.end method + +.method private getValue()Z + .registers 2 + const/4 v0, 0x0 + return v0 +.end method + +.method private use1(Ljava/lang/Integer;)V + .registers 2 + return-void +.end method + +.method private use2(I)V + .registers 2 + return-void +.end method