Skip to content

Commit

Permalink
fix: add cast for null in overloaded methods (#636) (PR #637)
Browse files Browse the repository at this point in the history
  • Loading branch information
asashour authored and skylot committed Apr 25, 2019
1 parent e7e7b66 commit 77cee15
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,10 @@ private boolean processOverloadedArg(CodeWriter code, MethodNode callMth, InsnAr
}
}
ArgType argType = arg.getType();
if (argType.equals(origType)) {
if (argType.equals(origType)
// null cast to object
&& (!arg.isLiteral() || ((LiteralArg) arg).getLiteral() != 0
|| (!argType.isArray() && !argType.isObject()))) {
return false;
}
if (origType.isGeneric()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package jadx.tests.integration.others;

import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.jupiter.api.Test;

import jadx.NotYetImplemented;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;

public class TestCastOfNull extends IntegrationTest {

public static class TestCls {

public void test() {
m((long[]) null);
m((String) null);
}

public void m(long[] a) {
}
public void m(String s) {
}
}

@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();

assertThat(code, containsOne("m((long[]) null);"));
assertThat(code, containsOne("m((String) null);"));
}
}

0 comments on commit 77cee15

Please sign in to comment.