Fix bug in decompiling nested catch blocks with complex control flow

This commit is contained in:
Alexey Andreev 2017-12-03 18:39:57 +03:00
parent 7b989a4c1c
commit c15709994f
2 changed files with 20 additions and 2 deletions

View File

@ -415,7 +415,7 @@ public class Decompiler {
} }
} }
for (int j = oldBlock.tryCatches.size() - 1; j >= 0; --j) { for (int j = 0; j < oldBlock.tryCatches.size(); ++j) {
TryCatchBookmark bookmark = oldBlock.tryCatches.get(j); TryCatchBookmark bookmark = oldBlock.tryCatches.get(j);
TryCatchStatement tryCatchStmt = new TryCatchStatement(); TryCatchStatement tryCatchStmt = new TryCatchStatement();
tryCatchStmt.setExceptionType(bookmark.exceptionType); tryCatchStmt.setExceptionType(bookmark.exceptionType);
@ -428,7 +428,7 @@ public class Decompiler {
if (!tryCatchStmt.getProtectedBody().isEmpty()) { if (!tryCatchStmt.getProtectedBody().isEmpty()) {
blockPart.add(tryCatchStmt); blockPart.add(tryCatchStmt);
} }
inheritedBookmarks.add(bookmark); inheritedBookmarks.add(0, bookmark);
} }
oldBlock.tryCatches.clear(); oldBlock.tryCatches.clear();
} }

View File

@ -101,6 +101,24 @@ public class VMTest {
assertEquals("before;inside;after;finally;", sb.toString()); assertEquals("before;inside;after;finally;", sb.toString());
} }
@Test
public void catchFinally() {
StringBuilder sb = new StringBuilder();
try {
if (Integer.parseInt("invalid") > 0) {
sb.append("err1;");
} else {
sb.append("err2;");
}
sb.append("err3");
} catch (NumberFormatException e) {
sb.append("catch;");
} finally {
sb.append("finally;");
}
assertEquals("catch;finally;", sb.toString());
}
@Test @Test
public void surrogateInStringLiteralsWork() { public void surrogateInStringLiteralsWork() {
assertEquals(0xDDC2, "a\uDDC2b".charAt(1)); assertEquals(0xDDC2, "a\uDDC2b".charAt(1));