fix: always cast null objects in overloaded method (#707)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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);"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user