From 8d68d409eb9c27f71d53b54e4ee4c879debf17a8 Mon Sep 17 00:00:00 2001 From: Skylot Date: Sun, 28 Jul 2019 21:09:56 +0300 Subject: [PATCH] test: another deboxing issue --- .../core/dex/visitors/DeboxingVisitor.java | 7 +++ .../integration/others/TestDeboxing3.java | 1 - .../integration/others/TestDeboxing4.java | 50 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing4.java diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/DeboxingVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/DeboxingVisitor.java index 1c20d4221..e18102eca 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/DeboxingVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/DeboxingVisitor.java @@ -98,13 +98,20 @@ public class DeboxingVisitor extends AbstractVisitor { arg.add(AFlag.EXPLICIT_PRIMITIVE_TYPE); } arg.setType(primitiveType); + boolean forbidInline; if (canChangeTypeToPrimitive(resArg)) { resArg.setType(primitiveType); + forbidInline = false; + } else { + forbidInline = true; } InsnNode constInsn = new InsnNode(InsnType.CONST, 1); constInsn.addArg(arg); constInsn.setResult(resArg); + if (forbidInline) { + constInsn.add(AFlag.DONT_INLINE); + } return constInsn; } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java index 0aebcb20d..dd7a57b56 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java @@ -55,6 +55,5 @@ public class TestDeboxing3 extends IntegrationTest { assertThat(code, containsOne("Pair pair = this.cache.get(id);")); assertThat(code, containsOne("return pair.first + l > System.currentTimeMillis();")); - } } diff --git a/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing4.java b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing4.java new file mode 100644 index 000000000..07ed3efaf --- /dev/null +++ b/jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing4.java @@ -0,0 +1,50 @@ +package jadx.tests.integration.others; + +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; + +import jadx.NotYetImplemented; +import jadx.core.dex.nodes.ClassNode; +import jadx.tests.api.IntegrationTest; + +import static jadx.tests.api.utils.JadxMatchers.containsOne; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; + +public class TestDeboxing4 extends IntegrationTest { + + public static class TestCls { + + public boolean test(Integer i) { + return ((Integer) 1).equals(i); + } + + public void check() { + assertThat(test(null), Matchers.is(false)); + assertThat(test(0), Matchers.is(false)); + assertThat(test(1), Matchers.is(true)); + } + } + + @Test + public void test() { + noDebugInfo(); + + ClassNode cls = getClassNode(TestCls.class); + String code = cls.getCode().toString(); + + assertThat(code, not(containsString("return 1.equals(num);"))); + } + + @Test + @NotYetImplemented("Inline boxed types") + public void testInline() { + noDebugInfo(); + + ClassNode cls = getClassNode(TestCls.class); + String code = cls.getCode().toString(); + + assertThat(code, containsOne("return ((Integer) 1).equals(i);")); + } +}