core: don't insert break in method exit blocks (fix #60)
This commit is contained in:
@@ -353,9 +353,12 @@ public class RegionMaker {
|
||||
return false;
|
||||
}
|
||||
List<BlockNode> simplePath = BlockUtils.buildSimplePath(exit);
|
||||
if (!simplePath.isEmpty()
|
||||
&& simplePath.get(simplePath.size() - 1).contains(AFlag.RETURN)) {
|
||||
return false;
|
||||
if (!simplePath.isEmpty()) {
|
||||
BlockNode lastBlock = simplePath.get(simplePath.size() - 1);
|
||||
if (lastBlock.contains(AFlag.RETURN)
|
||||
|| lastBlock.getSuccessors().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// check if there no outer switch (TODO: very expensive check)
|
||||
Set<BlockNode> paths = BlockUtils.getAllPathsBlocks(mth.getEnterBlock(), exit);
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package jadx.tests.integration.loops;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestBreakInLoop2 extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
public void test(List<Integer> data) throws Exception {
|
||||
for (; ; ) {
|
||||
try {
|
||||
funcB(data);
|
||||
break;
|
||||
} catch (Exception ex) {
|
||||
if (funcC()) {
|
||||
throw ex;
|
||||
}
|
||||
data.clear();
|
||||
}
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean funcB(List<Integer> data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean funcC() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne("while (true) {"));
|
||||
assertThat(code, containsOne("break;"));
|
||||
assertThat(code, containsOne("throw ex;"));
|
||||
assertThat(code, containsOne("data.clear();"));
|
||||
assertThat(code, containsOne("Thread.sleep(100);"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user