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 {
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();
if (argType.equals(origType)
// null cast to object
&& (!arg.isLiteral() || ((LiteralArg) arg).getLiteral() != 0
|| (!argType.isArray() && !argType.isObject()))) {
if (arg.isLiteral() && ((LiteralArg) arg).getLiteral() == 0
&& (argType.isObject() || argType.isArray())) {
return true;
}
if (argType.equals(origType)) {
return false;
}
if (origType.isGeneric()) {
......@@ -828,9 +839,6 @@ public class InsnGen {
((InsnWrapArg) arg).getWrapInsn().add(AFlag.EXPLICIT_GENERICS);
}
}
code.add('(');
useType(code, origType);
code.add(") ");
return true;
}
......
package jadx.tests.integration.others;
import java.util.List;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
......@@ -15,6 +17,7 @@ public class TestCastOfNull extends IntegrationTest {
public void test() {
m((long[]) null);
m((String) null);
m((List<String>) null);
}
public void m(long[] a) {
......@@ -22,6 +25,9 @@ public class TestCastOfNull extends IntegrationTest {
public void m(String s) {
}
public void m(List<String> list) {
}
}
@Test
......@@ -31,5 +37,6 @@ public class TestCastOfNull extends IntegrationTest {
assertThat(code, containsOne("m((long[]) 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