Skip to content

Commit

Permalink
fix: additional checks to forbid inline of null consts (#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Apr 19, 2023
1 parent 3fa3e5a commit 50283ab
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T2, Byte> t1 = (T1<T2, Byte>) null;
return t1.t2.l;
}

static class T2 {
public long l;
}

static class T1<H, P extends Byte> {
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);
}
}

0 comments on commit 50283ab

Please sign in to comment.