Commit d5740c1b authored by Skylot's avatar Skylot

core: fix 'finally' extract in 'if'

parent 3357979c
......@@ -34,6 +34,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static jadx.core.dex.visitors.blocksmaker.BlockSplitter.connect;
import static jadx.core.dex.visitors.blocksmaker.BlockSplitter.insertBlockBetween;
import static jadx.core.dex.visitors.blocksmaker.BlockSplitter.removeConnection;
public class BlockFinallyExtract extends AbstractVisitor {
......@@ -511,10 +512,11 @@ public class BlockFinallyExtract extends AbstractVisitor {
// redirect input edges
for (BlockNode pred : new ArrayList<BlockNode>(remBlock.getPredecessors())) {
removeConnection(pred, remBlock);
connect(pred, startBlock);
addIgnoredEdge(pred, startBlock);
connect(pred, rOut);
BlockNode middle = insertBlockBetween(mth, pred, remBlock);
removeConnection(middle, remBlock);
connect(middle, startBlock);
addIgnoredEdge(middle, startBlock);
connect(middle, rOut);
}
// mark blocks for remove
......
package jadx.tests.integration.trycatch;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertThat;
public class TestTryCatchFinally5 extends IntegrationTest {
public static class TestCls {
private <E> List<E> test(A a, B<E> b) {
C c = p(a);
if (c == null) {
return null;
}
D d = b.f(c);
try {
if (!d.first()) {
return null;
}
List<E> list = new ArrayList<E>();
do {
list.add(b.load(d));
} while (d.toNext());
return list;
} finally {
d.close();
}
}
private C p(A a) {
return (C) a;
}
private interface A {
}
private interface B<T> {
D f(C c);
T load(D d);
}
private interface C {
}
private interface D {
boolean first();
boolean toNext();
void close();
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("} finally {"));
// TODO: remove duplicates on multiple paths
// assertThat(code, containsOne("d.close();"));
}
}
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