提交 4ace552a 编写于 作者: S Skylot

core: fix duplicate cast

上级 b61daaed
package jadx.core.dex.visitors.typeresolver;
import jadx.core.dex.attributes.BlockRegState;
import jadx.core.dex.instructions.IndexInsnNode;
import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.nodes.BlockNode;
......@@ -20,8 +17,6 @@ public class TypeResolver extends AbstractVisitor {
if (mth.isNoCode()) {
return;
}
prepare(mth);
visitBlocks(mth);
visitEdges(mth);
......@@ -32,20 +27,6 @@ public class TypeResolver extends AbstractVisitor {
}
}
/**
* Check argument types (can be broken after merging debug info)
*/
private static void prepare(MethodNode mth) {
for (BlockNode block : mth.getBasicBlocks()) {
for (InsnNode insn : block.getInstructions()) {
if (insn.getType() == InsnType.CHECK_CAST) {
ArgType castType = (ArgType) ((IndexInsnNode) insn).getIndex();
insn.getResult().getTypedVar().forceSetType(castType);
}
}
}
}
private static void visitBlocks(MethodNode mth) {
for (BlockNode block : mth.getBasicBlocks()) {
BlockRegState state = new BlockRegState(mth);
......
package jadx.core.dex.visitors.typeresolver.finish;
import jadx.core.dex.info.MethodInfo;
import jadx.core.dex.instructions.IndexInsnNode;
import jadx.core.dex.instructions.InvokeNode;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg;
......@@ -85,6 +86,13 @@ public class PostTypeResolver {
return change;
}
case CHECK_CAST: {
ArgType castType = (ArgType) ((IndexInsnNode) insn).getIndex();
// workaround for compiler bug (see TestDuplicateCast)
insn.getResult().getTypedVar().forceSetType(castType);
return true;
}
default:
break;
}
......
......@@ -9,12 +9,18 @@ import jadx.core.dex.nodes.MethodNode;
import java.util.List;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
* Test duplicate 'check-cast' instruction produced because of bug in javac:
* http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6246854
*/
public class TestDuplicateCast extends InternalJadxTest {
public static class TestCls {
......@@ -23,7 +29,7 @@ public class TestDuplicateCast extends InternalJadxTest {
}
}
//@Test
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
MethodNode mth = getMethod(cls, "method");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册