Commit 12bb6323 authored by Skylot's avatar Skylot

fix: always cast null objects in overloaded method (#707)

parent e4fc6774
...@@ -807,11 +807,22 @@ public class InsnGen { ...@@ -807,11 +807,22 @@ public class InsnGen {
return false; return false;
} }
} }
if (isCastNeeded(arg, origType)) {
code.add('(');
useType(code, origType);
code.add(") ");
return true;
}
return false;
}
private boolean isCastNeeded(InsnArg arg, ArgType origType) {
ArgType argType = arg.getType(); ArgType argType = arg.getType();
if (argType.equals(origType) if (arg.isLiteral() && ((LiteralArg) arg).getLiteral() == 0
// null cast to object && (argType.isObject() || argType.isArray())) {
&& (!arg.isLiteral() || ((LiteralArg) arg).getLiteral() != 0 return true;
|| (!argType.isArray() && !argType.isObject()))) { }
if (argType.equals(origType)) {
return false; return false;
} }
if (origType.isGeneric()) { if (origType.isGeneric()) {
...@@ -828,9 +839,6 @@ public class InsnGen { ...@@ -828,9 +839,6 @@ public class InsnGen {
((InsnWrapArg) arg).getWrapInsn().add(AFlag.EXPLICIT_GENERICS); ((InsnWrapArg) arg).getWrapInsn().add(AFlag.EXPLICIT_GENERICS);
} }
} }
code.add('(');
useType(code, origType);
code.add(") ");
return true; return true;
} }
......
package jadx.tests.integration.others; package jadx.tests.integration.others;
import java.util.List;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.ClassNode;
...@@ -15,6 +17,7 @@ public class TestCastOfNull extends IntegrationTest { ...@@ -15,6 +17,7 @@ public class TestCastOfNull extends IntegrationTest {
public void test() { public void test() {
m((long[]) null); m((long[]) null);
m((String) null); m((String) null);
m((List<String>) null);
} }
public void m(long[] a) { public void m(long[] a) {
...@@ -22,6 +25,9 @@ public class TestCastOfNull extends IntegrationTest { ...@@ -22,6 +25,9 @@ public class TestCastOfNull extends IntegrationTest {
public void m(String s) { public void m(String s) {
} }
public void m(List<String> list) {
}
} }
@Test @Test
...@@ -31,5 +37,6 @@ public class TestCastOfNull extends IntegrationTest { ...@@ -31,5 +37,6 @@ public class TestCastOfNull extends IntegrationTest {
assertThat(code, containsOne("m((long[]) null);")); assertThat(code, containsOne("m((long[]) null);"));
assertThat(code, containsOne("m((String) null);")); assertThat(code, containsOne("m((String) null);"));
assertThat(code, containsOne("m((List<String>) null);"));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment