core: fix processing 'if' at loop end

This commit is contained in:
Skylot
2014-08-20 22:00:44 +04:00
parent 627a4dc802
commit ec8309af49
2 changed files with 50 additions and 2 deletions
@@ -47,8 +47,8 @@ public class IfMakerHelper {
info.setOutBlock(null);
return info;
}
boolean badThen = !allPathsFromIf(thenBlock, info);
boolean badElse = !allPathsFromIf(elseBlock, info);
boolean badThen = thenBlock.contains(AFlag.LOOP_START) || !allPathsFromIf(thenBlock, info);
boolean badElse = elseBlock.contains(AFlag.LOOP_START) || !allPathsFromIf(elseBlock, info);
if (badThen && badElse) {
LOG.debug("Stop processing blocks after 'if': {}, method: {}", info.getIfBlock(), mth);
return null;
@@ -0,0 +1,48 @@
package jadx.tests.internal.loops;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import java.util.Iterator;
import org.junit.Test;
import static jadx.tests.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertThat;
public class TestLoopDetection4 extends InternalJadxTest {
public static class TestCls {
private Iterator<String> iterator;
private SomeCls filter;
private String test() {
while (iterator.hasNext()) {
String next = iterator.next();
String filtered = filter.filter(next);
if (filtered != null) {
return filtered;
}
}
return null;
}
private class SomeCls {
public String filter(String str) {
return str;
}
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, containsOne("while (this.iterator.hasNext()) {"));
assertThat(code, containsOne("if (filtered != null) {"));
assertThat(code, containsOne("return filtered;"));
assertThat(code, containsOne("return null;"));
}
}