Commit 543cad3a authored by skylot's avatar skylot

Merge pull request #11 from Fruiter/master

core: fix nested try-catch blocks processing
parents ce7101be 41cc83db
......@@ -101,10 +101,14 @@ public class ProcessTryCatchRegions extends AbstractRegionVisitor {
// search dominator blocks in this region (don't need to go deeper)
for (BlockNode dominator : tryBlocksMap.keySet()) {
if (region.getSubBlocks().contains(dominator)) {
wrapBlocks(region, dominator);
Region newRegion = wrapBlocks(region, dominator);
tryBlocksMap.remove(dominator);
// if region is modified rerun this method
leaveRegion(mth, region);
if (newRegion != null) {
// dominator may be moved into new region
leaveRegion(mth, newRegion);
// if region is modified rerun this method
leaveRegion(mth, region);
}
return;
}
}
......@@ -113,7 +117,7 @@ public class ProcessTryCatchRegions extends AbstractRegionVisitor {
/**
* Extract all block dominated by 'dominator' to separate region and mark as try/catch block
*/
private void wrapBlocks(IRegion region, BlockNode dominator) {
private Region wrapBlocks(IRegion region, BlockNode dominator) {
Region newRegion = new Region(region);
TryCatchBlock tb = tryBlocksMap.get(dominator);
assert tb != null;
......@@ -127,7 +131,7 @@ public class ProcessTryCatchRegions extends AbstractRegionVisitor {
}
}
if (newRegion.getSubBlocks().isEmpty()) {
return;
return null;
}
if (DEBUG) {
LOG.debug("ProcessTryCatchRegions mark: {}", newRegion);
......@@ -147,6 +151,8 @@ public class ProcessTryCatchRegions extends AbstractRegionVisitor {
aReg.setParent(newRegion);
}
}
return newRegion;
}
private boolean isHandlerPath(TryCatchBlock tb, IContainer cont) {
......
package jadx.tests.internal.trycatch;
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 TestNestedTryCatch extends InternalJadxTest {
public static class TestCls {
private void f() {
try {
Thread.sleep(1);
try {
Thread.sleep(2);
} catch (InterruptedException e) {
}
} catch (Exception e) {
}
return;
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsString("try {"));
assertThat(code, containsString("Thread.sleep(1);"));
assertThat(code, containsString("Thread.sleep(2);"));
assertThat(code, containsString("} catch (InterruptedException e) {"));
assertThat(code, containsString("} catch (Exception e2) {"));
assertThat(code, not(containsString("return")));
}
}
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