diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlineVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlineVisitor.java index ab1d3a5773b..564584d478f 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlineVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlineVisitor.java @@ -125,17 +125,30 @@ private static boolean forbidNullInlines(SSAVar sVar) { int k = 0; for (RegisterArg useArg : useList) { InsnNode insn = useArg.getParentInsn(); - if (insn == null) { - continue; - } - if (!canUseNull(insn, useArg)) { - useArg.add(AFlag.DONT_INLINE_CONST); + if (insn != null && forbidNullArgInline(insn, useArg)) { k++; } } return k == useList.size(); } + private static boolean forbidNullArgInline(InsnNode insn, RegisterArg useArg) { + switch (insn.getType()) { + case MOVE: + case CAST: + case CHECK_CAST: + // result is null, chain checks + return forbidNullInlines(insn.getResult().getSVar()); + + default: + if (!canUseNull(insn, useArg)) { + useArg.add(AFlag.DONT_INLINE_CONST); + return true; + } + return false; + } + } + private static boolean canUseNull(InsnNode insn, RegisterArg useArg) { switch (insn.getType()) { case INVOKE: diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestNullInline.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestNullInline.java new file mode 100644 index 00000000000..92979c6f7f5 --- /dev/null +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestNullInline.java @@ -0,0 +1,43 @@ +package jadx.tests.integration.others; + +import org.junit.jupiter.api.Test; + +import jadx.tests.api.IntegrationTest; + +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; + +public class TestNullInline extends IntegrationTest { + + @SuppressWarnings({ "RedundantCast", "DataFlowIssue", "unused" }) + public static class TestCls { + public static Long test(Double d1) { + T1 t1 = (T1) null; + return t1.t2.l; + } + + static class T2 { + public long l; + } + + static class T1 { + public T2 t2; + + public T1(T2 t2) { + this.t2 = t2; + } + } + } + + @Test + public void test() { + assertThat(getClassNode(TestCls.class)) + .code() + .containsOne("Long.valueOf(t1.t2.l);"); + } + + @Test + public void testNoDebug() { + noDebugInfo(); + getClassNode(TestCls.class); + } +}