core: fix signature processing for local variables
This commit is contained in:
@@ -374,7 +374,7 @@ public abstract class ArgType {
|
||||
}
|
||||
|
||||
public String getObject() {
|
||||
throw new UnsupportedOperationException("ArgType.getObject()");
|
||||
throw new UnsupportedOperationException("ArgType.getObject(), call class: " + this.getClass());
|
||||
}
|
||||
|
||||
public boolean isObject() {
|
||||
|
||||
@@ -34,9 +34,13 @@ final class LocalVar extends RegisterArg {
|
||||
|
||||
private void init(String name, ArgType type, String sign) {
|
||||
if (sign != null) {
|
||||
ArgType gType = ArgType.generic(sign);
|
||||
if (checkSignature(type, sign, gType)) {
|
||||
type = gType;
|
||||
try {
|
||||
ArgType gType = ArgType.generic(sign);
|
||||
if (checkSignature(type, sign, gType)) {
|
||||
type = gType;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Can't parse signature for local variable: " + sign, e);
|
||||
}
|
||||
}
|
||||
TypedVar tv = new TypedVar(type);
|
||||
@@ -45,10 +49,10 @@ final class LocalVar extends RegisterArg {
|
||||
}
|
||||
|
||||
private boolean checkSignature(ArgType type, String sign, ArgType gType) {
|
||||
boolean apply = false;
|
||||
boolean apply;
|
||||
ArgType el = gType.getArrayRootElement();
|
||||
if (el.isGeneric()) {
|
||||
if (!type.getObject().equals(el.getObject())) {
|
||||
if (!type.getArrayRootElement().getObject().equals(el.getObject())) {
|
||||
LOG.warn("Generic type in debug info not equals: {} != {}", type, gType);
|
||||
}
|
||||
apply = true;
|
||||
@@ -56,6 +60,7 @@ final class LocalVar extends RegisterArg {
|
||||
apply = true;
|
||||
} else {
|
||||
LOG.debug("Local var signature from debug info not generic: {}, parsed: {}", sign, gType);
|
||||
apply = false;
|
||||
}
|
||||
return apply;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package jadx.tests.internal.generics;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestGenerics4 extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
public static Class<?> method(int i) {
|
||||
Class<?>[] a = new Class<?>[0];
|
||||
return a[a.length - i];
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsString("Class<?>[] a ="));
|
||||
assertThat(code, not(containsString("Class[] a =")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user