Commit 7a51c0d0 authored by Skylot's avatar Skylot

core: fix signature processing for local variables

parent 8762125b
......@@ -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;
}
......
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 =")));
}
}
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