Commit a234227b authored by Skylot's avatar Skylot

core: fix errors in try/catch processing (issue #13)

parent 16f736e7
......@@ -259,6 +259,7 @@ public class MethodNode extends LineAttrNode implements ILoadable {
if (ct1 != ct2 && ct2.containsAllHandlers(ct1)) {
for (ExceptionHandler h : ct1.getHandlers()) {
ct2.removeHandler(this, h);
h.setTryBlock(ct1);
}
}
}
......
......@@ -273,13 +273,15 @@ public class RegionMaker {
}
Region body = makeRegion(loopStart, stack);
if (!RegionUtils.isRegionContainsBlock(body, loop.getEnd())) {
body.getSubBlocks().add(loop.getEnd());
BlockNode loopEnd = loop.getEnd();
if (!RegionUtils.isRegionContainsBlock(body, loopEnd)
&& !loopEnd.contains(AType.EXC_HANDLER)) {
body.getSubBlocks().add(loopEnd);
}
loopRegion.setBody(body);
if (loopExit == null) {
BlockNode next = getNextBlock(loop.getEnd());
BlockNode next = getNextBlock(loopEnd);
loopExit = RegionUtils.isRegionContainsBlock(body, next) ? null : next;
}
stack.pop();
......
......@@ -255,7 +255,7 @@ public class BlockUtils {
}
BitSet b = new BitSet();
b.or(b1.getDomFrontier());
b.or(b2.getDomFrontier());
b.and(b2.getDomFrontier());
b.clear(b1.getId());
b.clear(b2.getId());
if (b.cardinality() == 1) {
......
......@@ -11,12 +11,14 @@ import org.junit.Test;
import static jadx.tests.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertThat;
public class TestIssue13 extends InternalJadxTest {
public class TestIssue13a extends InternalJadxTest {
public static class TestCls {
private static final String TAG = "Parcel";
private static HashMap<ClassLoader, HashMap<String, Parcelable.Creator>> mCreators;
private static final HashMap<ClassLoader, HashMap<String, Parcelable.Creator>>
mCreators = new HashMap<ClassLoader, HashMap<String, Parcelable.Creator>>();
@SuppressWarnings("unchecked")
public final <T extends Parcelable> T test(ClassLoader loader) {
String name = readString();
if (name == null) {
......
package jadx.tests.internal.others;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import org.junit.Test;
import static jadx.tests.utils.JadxMatchers.containsOne;
import static jadx.tests.utils.JadxMatchers.countString;
import static org.junit.Assert.assertThat;
public class TestIssue13b extends InternalJadxTest {
public static class TestCls {
private static final String PROPERTIES_FILE = "";
private static final String TAG = "";
private final CountDownLatch mInitializedLatch = new CountDownLatch(1);
private int mC2KServerPort = 0;
private String mSuplServerHost = "";
private int mSuplServerPort = 0;
private String mC2KServerHost = "";
public TestCls() {
Properties mProperties = new Properties();
try {
File file = new File(PROPERTIES_FILE);
FileInputStream stream = new FileInputStream(file);
mProperties.load(stream);
stream.close();
mSuplServerHost = mProperties.getProperty("SUPL_HOST");
String portString = mProperties.getProperty("SUPL_PORT");
if (mSuplServerHost != null && portString != null) {
try {
mSuplServerPort = Integer.parseInt(portString);
} catch (NumberFormatException e) {
Log.e(TAG, "unable to parse SUPL_PORT: " + portString);
}
}
mC2KServerHost = mProperties.getProperty("C2K_HOST");
portString = mProperties.getProperty("C2K_PORT");
if (mC2KServerHost != null && portString != null) {
try {
mC2KServerPort = Integer.parseInt(portString);
} catch (NumberFormatException e) {
Log.e(TAG, "unable to parse C2K_PORT: " + portString);
}
}
} catch (IOException e) {
Log.e(TAG, "Could not open GPS configuration file " + PROPERTIES_FILE);
}
Thread mThread = new Thread();
mThread.start();
while (true) {
try {
mInitializedLatch.await();
break;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
private static class Log {
public static void e(String tag, String s) {
}
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, countString(4, "} catch ("));
assertThat(code, countString(3, "Log.e("));
assertThat(code, containsOne("Thread.currentThread().interrupt();"));
}
}
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