Skip to content

Commit

Permalink
fix: don't cast overloaded methods with generics from other class (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Mar 30, 2019
1 parent 4a92275 commit 008216d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ private boolean processOverloadedArg(CodeWriter code, MethodNode callMth, InsnAr
origType = callMth.getMethodInfo().getArgumentsTypes().get(origPos);
} else {
origType = arguments.get(origPos).getInitType();
if (origType.isGenericType() && !callMth.getParentClass().equals(mth.getParentClass())) {
// cancel cast
return false;
}
}
if (!arg.getType().equals(origType)) {
code.add('(');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package jadx.tests.integration.invoke;

import org.junit.jupiter.api.Test;

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

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

public class TestSuperInvokeWithGenerics extends IntegrationTest {

public static class TestCls {

public class A<T extends Exception, V> {
public A(T t) {
System.out.println("t" + t);
}

public A(V v) {
System.out.println("v" + v);
}
}

public class B extends A<Exception, String> {
public B(String s) {
super(s);
}

public B(Exception e) {
super(e);
}
}
}

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

assertThat(code, containsOne("super(e);"));
assertThat(code, containsOne("super(s);"));
}
}

0 comments on commit 008216d

Please sign in to comment.