fix: handle empty loop body (#1040)
This commit is contained in:
@@ -8,6 +8,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -224,7 +225,13 @@ public class RegionMaker {
|
||||
}
|
||||
stack.addExit(out);
|
||||
BlockNode loopBody = condInfo.getThenBlock();
|
||||
Region body = makeRegion(loopBody, stack);
|
||||
Region body;
|
||||
if (Objects.equals(loopBody, loopStart)) {
|
||||
// empty loop body
|
||||
body = new Region(loopRegion);
|
||||
} else {
|
||||
body = makeRegion(loopBody, stack);
|
||||
}
|
||||
// add blocks from loop start to first condition block
|
||||
BlockNode conditionBlock = condInfo.getIfBlock();
|
||||
if (loopStart != conditionBlock) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.Iterator;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.NotYetImplemented;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
@@ -23,11 +22,11 @@ public class TestDoWhileBreak3 extends IntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@NotYetImplemented
|
||||
@Test
|
||||
public void test() {
|
||||
assertThat(getClassNode(TestCls.class))
|
||||
.code()
|
||||
.containsOnlyOnce("while");
|
||||
.containsOne("while")
|
||||
.containsLines(2, "while (this.it.hasNext() && this.it.next() != null) {", "}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user