From 0dfc1c33422f575d8e1536ba7c32f3fa982c616e Mon Sep 17 00:00:00 2001 From: Yohann Roussel Date: Thu, 4 Sep 2014 19:11:23 +0200 Subject: Fix illegal code generation of TryWithResourcesTransformer - Add a test for try with resources that exhibit illegal code generation. - Add generation of throw instruction to have correct java code at compile time. Bug: 17389106 Change-Id: I451adb03917b5908faf2a7730990c474009706d2 --- .../java7/trywithresources/test002/dx/Tests.java | 5 +++++ .../test002/jack/TryWithResourcesTest002.java | 24 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'jack-tests') diff --git a/jack-tests/tests/com/android/jack/java7/trywithresources/test002/dx/Tests.java b/jack-tests/tests/com/android/jack/java7/trywithresources/test002/dx/Tests.java index aa47320..641274d 100644 --- a/jack-tests/tests/com/android/jack/java7/trywithresources/test002/dx/Tests.java +++ b/jack-tests/tests/com/android/jack/java7/trywithresources/test002/dx/Tests.java @@ -91,4 +91,9 @@ import org.junit.Test; public void test013() { Assert.assertTrue(TryWithResourcesTest002.m13()); } + + @Test + public void test014() throws Exception { + Assert.assertTrue(TryWithResourcesTest002.m14(1)); + } } diff --git a/jack-tests/tests/com/android/jack/java7/trywithresources/test002/jack/TryWithResourcesTest002.java b/jack-tests/tests/com/android/jack/java7/trywithresources/test002/jack/TryWithResourcesTest002.java index 5b9ea0e..6a58bc3 100644 --- a/jack-tests/tests/com/android/jack/java7/trywithresources/test002/jack/TryWithResourcesTest002.java +++ b/jack-tests/tests/com/android/jack/java7/trywithresources/test002/jack/TryWithResourcesTest002.java @@ -270,4 +270,28 @@ public class TryWithResourcesTest002 { return result; } + private static boolean getMaybeThrow(int condition) throws E1 { + if (condition < 5) { + return true; + } else if (condition > 15) { + return false; + } + throw new E1(); + } + + public static boolean m14(int condition) throws Exception { + Observer o1 = new Observer(); + try ( + AutoCloseable001 ac1 = new AutoCloseable001(o1); + ) { + if (condition < 10) { + return getMaybeThrow(condition + 2); + } + return getMaybeThrow(condition); + // No exception + } catch (E1 e) { + return getMaybeThrow(condition - 10); + } + } + } -- cgit v1.1