diff options
author | Yohann Roussel <yroussel@google.com> | 2014-03-19 16:25:37 +0100 |
---|---|---|
committer | Yohann Roussel <yroussel@google.com> | 2014-03-20 15:13:33 +0100 |
commit | 4eceb95409e844fdc33c9c706e1dc307bfd40303 (patch) | |
tree | ee9f4f3fc79f757c79081c336bce4f1782c6ccd8 /jack-tests/tests/com/android/jack/tryfinally | |
parent | 3d2402901b1a6462e2cf47a6fd09711f327961c3 (diff) | |
download | toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.zip toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.tar.gz toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.tar.bz2 |
Initial Jack import.
Change-Id: I953cf0a520195a7187d791b2885848ad0d5a9b43
Diffstat (limited to 'jack-tests/tests/com/android/jack/tryfinally')
14 files changed, 1744 insertions, 0 deletions
diff --git a/jack-tests/tests/com/android/jack/tryfinally/finally002/dx/Tests.java b/jack-tests/tests/com/android/jack/tryfinally/finally002/dx/Tests.java new file mode 100644 index 0000000..fe76cb1 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finally002/dx/Tests.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finally002.dx; + +import com.android.jack.tryfinally.finally002.jack.Data; + +import junit.framework.Assert; + +import org.junit.Test; + +public class Tests { + @Test + public void test001() { + Assert.assertEquals(8, Data.get001(1)); + } + + @Test + public void test002() { + Assert.assertEquals(10, Data.get001(2)); + } + + @Test + public void test003() { + Assert.assertEquals(14, Data.get001(3)); + } + + @Test + public void test004() { + Assert.assertEquals(3, Data.get001(4)); + } + + @Test + public void test005() { + Assert.assertEquals(66, Data.get002(-1)); + } + + @Test + public void test006() { + Assert.assertEquals(32, Data.get002(1)); + } + + @Test + public void test007() { + Assert.assertEquals(37, Data.get003(-1)); + } + + @Test + public void test008() { + Assert.assertEquals(33, Data.get003(1)); + } + + @Test + public void test009() { + try { + Data.get004(); + Assert.fail(); + } catch (NullPointerException e) { + // OK + } + } + + @Test + public void test010() { + Assert.assertEquals(3, Data.get005()); + } + + @Test + public void test011() { + try { + Assert.assertEquals(3, Data.get006()); + Assert.fail(); + } catch (NullPointerException e) { + //Ok + } + } + + @Test + public void test012() { + Assert.assertEquals(1, Data.get007()); + Assert.assertEquals(0, Data.field007); + } +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finally002/jack/Data.java b/jack-tests/tests/com/android/jack/tryfinally/finally002/jack/Data.java new file mode 100644 index 0000000..df51fa5 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finally002/jack/Data.java @@ -0,0 +1,240 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finally002.jack; + +public class Data { + + public static int get001(int i) { + int result = 0; + try { + alwaysThrow(); + } catch (Exception e) { + try { + try { + try { + try { + canThrow(i); + } finally { + result += 3; + } + } catch (NullPointerException npe) { + result += 5; + } + } catch (OutOfMemoryError oom) { + result += 7; + } + } catch (TestException te) { + result += 11; + } + } + return result; + } + + public static int get002(int i) { + int result = 0; + try { + try { + alwaysThrow(); + } catch (Exception e) { + try { + alwaysThrow(); + } catch (Exception e2) { + try { + alwaysThrow(); + } catch (Exception e3) { + try { + alwaysThrow(); + } catch (Exception e4) { + try { + alwaysThrow(); + } catch (Exception e5) { + try { + canThrow(i); + } finally { + result += 3; + } + result += 5; + } + result += 7; + + } + result += 11; + + } + result += 17; + + } + result += 23; + + } + } catch (Exception e) { + result += 29; + } + return result; + } + + public static int get003(int i) { + int result = 0; + try { + try { + alwaysThrow(); + } catch (Exception e2) { + try { + alwaysThrow(); + } catch (Exception e3) { + try { + alwaysThrow(); + } catch (Exception e5) { + result += 1; + } finally { + try { + canThrow(i); + } finally { + result += 3; + } + result += 5; + + } + result += 11; + + } + result += 17; + + } + } catch (Exception e) { + result += 29; + } + return result; + } + + @SuppressWarnings("finally") + public static int get004() { + try { + throw new ArrayIndexOutOfBoundsException(); + } catch (ArrayIndexOutOfBoundsException e) { + try { + throw new ArrayIndexOutOfBoundsException(); + } catch (ArrayIndexOutOfBoundsException e1) { + try { + return 1; + } finally { + throw new NullPointerException(); + } + } + } catch (NullPointerException e) { + return 2; + } + } + + @SuppressWarnings("finally") + public static int get005() { + try { + throw new ArrayIndexOutOfBoundsException(); + } catch (ArrayIndexOutOfBoundsException e) { + try { + throw new ArrayIndexOutOfBoundsException(); + } catch (ArrayIndexOutOfBoundsException e1) { + try { + return 1; + } finally { + throw new NullPointerException(); + } + } + } catch (NullPointerException e) { + return 2; + } finally { + return 3; + } + } + + @SuppressWarnings("finally") + public static int get005Bis() { + try { + throw new ArrayIndexOutOfBoundsException(); + } catch (ArrayIndexOutOfBoundsException e) { + try { + throw new ArrayIndexOutOfBoundsException(); + } catch (ArrayIndexOutOfBoundsException e1) { + try { + return 1; + } finally { + throw new NullPointerException(); + } + } + } catch (NullPointerException e) { + return 2; + } finally { + return 3; + } + } + + @SuppressWarnings("finally") + public static int get006() { + try { + return 1; + } finally { + try { + return 2; + } finally { + try { + return 3; + } finally { + throw new NullPointerException(); + } + } + } + } + + public static int field007; + + @SuppressWarnings("finally") + public static int get007() { + field007 = 0; + try { + return 1; + } + catch (NullPointerException e) { + field007 = 4; + return 4; + } + catch (ArrayIndexOutOfBoundsException e) { + try { + return 2; + } finally { + try { + return 3; + } finally { + throw new NullPointerException(); + } + } + } + } + + private static void canThrow(int i) throws TestException { + switch (i) { + case 1 : + throw new NullPointerException(); + case 2 : + throw new OutOfMemoryError(); + case 3 : + throw new TestException(); + } + } + private static void alwaysThrow() throws TestException { + throw new TestException(); + } +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finally002/jack/TestException.java b/jack-tests/tests/com/android/jack/tryfinally/finally002/jack/TestException.java new file mode 100644 index 0000000..1f22ba4 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finally002/jack/TestException.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finally002.jack; + +public class TestException extends Exception { + + private static final long serialVersionUID = 1L; + + public TestException() { + } + + public TestException(String message) { + super(message); + } + + public TestException(Throwable cause) { + super(cause); + } + + public TestException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finally003/dx/Tests.java b/jack-tests/tests/com/android/jack/tryfinally/finally003/dx/Tests.java new file mode 100644 index 0000000..8492a80 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finally003/dx/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finally003.dx; + +import com.android.jack.tryfinally.finally003.jack.Finally003; + +import junit.framework.Assert; + +import org.junit.Test; + +public class Tests { + + @Test + public void test001() { + Assert.assertEquals(19, Finally003.get()); + } + +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finally003/jack/Finally003.java b/jack-tests/tests/com/android/jack/tryfinally/finally003/jack/Finally003.java new file mode 100644 index 0000000..584b90e --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finally003/jack/Finally003.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finally003.jack; + +public class Finally003 { + + public static int get() { + int i = 0; + try { + i += 12; + canThrow(); + } finally { + switch (i) { + case 0 : + i += 5; + default : + i += 7; + } + } + return i; + } + + private static void canThrow() { + // + } + +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finally004/dx/Tests.java b/jack-tests/tests/com/android/jack/tryfinally/finally004/dx/Tests.java new file mode 100644 index 0000000..f4b8663 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finally004/dx/Tests.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finally004.dx; + +import com.android.jack.tryfinally.finally004.jack.Finally004; + +import junit.framework.Assert; + +import org.junit.Test; + +public class Tests { + + @Test + public void test001() { + Assert.assertEquals(0, Finally004.get()); + } + +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finally004/jack/Finally004.java b/jack-tests/tests/com/android/jack/tryfinally/finally004/jack/Finally004.java new file mode 100644 index 0000000..9c47f81 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finally004/jack/Finally004.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finally004.jack; + +public class Finally004 { + + public static int get() { + boolean satisfied = false; + try { + satisfied = getSatisfied(); + return 0; + } finally { + if (!satisfied) { + return 1; + } + } + } + + private static boolean getSatisfied() { + return true; + } +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finally005/jack/Finally005.java b/jack-tests/tests/com/android/jack/tryfinally/finally005/jack/Finally005.java new file mode 100644 index 0000000..c0f1c06 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finally005/jack/Finally005.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finally005.jack; + +/** + * JUnit test allowing to verify that useless 'if' are not generated (if null != null). + */ +public class Finally005 { + + private static class A { + public int i = 10; + + public void call() { + } + } + + public static A newA() { + return new A(); + } + + public static void get() { + A a = null; + try { + a = newA(); + } finally { + // After FinallyRemover and ConstantRefinerAndVariableRemover, the following if is no longer + // required and should be removed since it is similar to if (null != null). + if (a != null) { + int l = a.i; + a.i = 10; + a.call(); + } + } + } +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finallyblock/dx/Tests.java b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/dx/Tests.java new file mode 100644 index 0000000..e1a1aee --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/dx/Tests.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finallyblock.dx; + +import org.junit.Assert; +import org.junit.Test; + +import com.android.jack.tryfinally.finallyblock.jack.B; +import com.android.jack.tryfinally.finallyblock.jack.Branching; +import com.android.jack.tryfinally.finallyblock.jack.Catch; +import com.android.jack.tryfinally.finallyblock.jack.EmptyBlocks; +import com.android.jack.tryfinally.finallyblock.jack.Nested; + +/** + * Tests about finally. + */ +public class Tests { + + @Test + public void branching1() { + Assert.assertEquals(2 * 5, Branching.returnInFinally1()); + Assert.assertEquals(2 * 5, Branching.returnInFinally2()); + Assert.assertEquals(2 * 3 * 5, Branching.returnInFinally3()); + Assert.assertEquals(2 * 3, Branching.returnInTry1()); + Assert.assertEquals(2 * 7, Branching.returnInCatch1()); + Assert.assertEquals("A", Branching.returnInTry2()); + Assert.assertEquals(2 * 3, Branching.returnInTry3(new B()).field); + Assert.assertEquals(-1, Branching.breakInFinally1()); + Assert.assertEquals(4, Branching.continueInFinally1()); + Assert.assertEquals(27, Branching.returnInNestedTry(true)); + } + + @Test + public void catch1() { + Assert.assertEquals(2 * 3 * 5, Catch.tryCatchFinally1()); + Assert.assertEquals(2 * 5, Catch.tryCatchFinally2()); + } + + @Test + public void catch2() { + Assert.assertEquals(2 * 3 * 7 * 13, Catch.shouldNotCatch1()); + Assert.assertEquals(2 * 3 * 7 * 23, Catch.shouldNotCatch2()); + try { + Catch.shouldNotCatch3(); + Assert.fail(); + } catch (NullPointerException e) { + // OK + } + Assert.assertEquals(0, Catch.value); + } + + @Test + public void nested1() { + Assert.assertEquals(2 * 23 * 7 * 19 * 13 * 17 * 5, Nested.inTry1()); + Assert.assertEquals(2 * 23 * 7 * 11 * 13 * 17 * 5, Nested.inTry2()); + Assert.assertEquals(2 * 23 * 7 * 13 * 3 * 5, Nested.inTry3()); + Assert.assertEquals(2 * 23 * 7 * 11 * 13 * 3 * 5, Nested.inTry4()); + Assert.assertEquals(2 * 19 * 5, Nested.inCatch1()); + Assert.assertEquals(2 * 3 * 7 * 13 * 17 * 5, Nested.inCatch2()); + Assert.assertEquals(2 * 3 * 7 * 11 * 13 * 17 * 5, Nested.inCatch3()); + Assert.assertEquals(2 * 3 * 7 * 11 * 13 * 5 * 31, Nested.inCatch4()); + Assert.assertEquals(2 * 23 * 5 * 7 * 19 * 13 * 17, Nested.inFinally1()); + Assert.assertEquals(2 * 23 * 5 * 7 * 11 * 13 * 17, Nested.inFinally2()); + Assert.assertEquals(2 * 23 * 5 * 7 * 19 * 13 * 17, Nested.inFinally6()); + Assert.assertEquals(2 * 23 * 5 * 7 * 11 * 13 * 17, Nested.inFinally7()); + } + + @Test + public void nested2() { + Assert.assertEquals(2 * 23 * 7 * 29 * 13 * 3 * 5, Nested.inTry5()); + Assert.assertEquals(2 * 23 * 7 * 11 * 13 * 3 * 5, Nested.inTry6()); + Assert.assertEquals(2 * 3 * 7 * 13 * 5 * 31, Nested.inCatch5()); + Assert.assertEquals(2 * 3 * 7 * 11 * 13 * 5 * 31, Nested.inCatch6()); + Assert.assertEquals(2 * 23 * 5 * 7 * 11 * 13 * 31, Nested.inFinally3()); + Assert.assertEquals(2 * 23 * 5 * 7 * 19 * 13 * 31, Nested.inFinally4()); + Assert.assertEquals(2 * 23 * 5 * 7 * 11 * 13 * 31, Nested.inFinally5()); + Assert.assertEquals(2 * 23 * 5 * 7 * 11 * 13 * 31, Nested.inFinally8()); + Assert.assertEquals(2 * 23 * 5 * 7 * 19 * 13 * 31, Nested.inFinally9()); + Assert.assertEquals(2 * 23 * 5 * 7 * 11 * 13 * 31, Nested.inFinally10()); + } + + @Test + public void emptyBlocks() { + Assert.assertEquals(5, EmptyBlocks.emptyTry()); + Assert.assertEquals(2 * 3 * 5, EmptyBlocks.emptyCatch1()); + Assert.assertEquals(2 * 5, EmptyBlocks.emptyCatch2()); + Assert.assertEquals(2 * 3, EmptyBlocks.emptyFinally1()); + Assert.assertEquals(2 * 5, EmptyBlocks.emptyFinally2()); + Assert.assertEquals(1, EmptyBlocks.allEmpty()); + } + + @Test + public void finallyWithNew() { + Assert.assertEquals(2, Catch.finallyWithNew()); + } + + @Test + public void loopIntoTryFinally() { + Assert.assertEquals(6, Branching.loopIntoTryFinally()); + } + + @Test + public void nestedFinally() { + Assert.assertEquals(7, Nested.inFinally11()); + } +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/B.java b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/B.java new file mode 100644 index 0000000..dd6ab37 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/B.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finallyblock.jack; + +public class B { + public int field = 2; +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/Branching.java b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/Branching.java new file mode 100644 index 0000000..a51b096 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/Branching.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finallyblock.jack; + +@SuppressWarnings("finally") +public class Branching { + + public static void throwException() { + throw new RuntimeException(); + } + + public static void doNotThrowException() { + return; + } + + public static int returnInFinally1() { + int a = 1; + try { + a = a * 2; + throwException(); + a = a * 3; + } finally { + a = a * 5; + return a; + } + } + + public static int returnInFinally2() { + int a = 1; + try { + a = a * 2; + throwException(); + a = a * 3; + return a; + } finally { + a = a * 5; + return a; + } + } + + public static int returnInFinally3() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 3; + return a; + } finally { + a = a * 5; + return a; + } + } + + public static int returnInTry1() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 3; + return a; + } finally { + a = a * 5; + } + } + + public static int returnInCatch1() { + int a = 1; + try { + a = a * 2; + throwException(); + a = a * 3; + return a; + } catch (Exception e) { + a = a * 7; + return a; + } finally { + a = a * 5; + } + } + + public static String returnInTry2() { + String a = "A"; + try { + doNotThrowException(); + return a; + } finally { + a = "B"; + } + } + + public static B returnInTry3(B b) { + b.field = 1; + try { + b.field = b.field * 2; + return b; + } finally { + b.field = b.field * 3; + } + } + + public static int breakInFinally1() { + int a = 1; + while (true) { + try { + a = a * 2; + return a; + } finally { + a = a * 3; + break; + } + } + return -1; + } + + public static int continueInFinally1() { + int a = 5; + int i = 0; + while (i<4) { + try { + a = a * 2; + i++; + return a; + } finally { + a = a * 3; + continue; + } + } + return i; + } + + public static int loopIntoTryFinally() { + int i = 0; + try { + while (i<5) { + i++; + } + } + finally { + i++; + } + return i; + } + + public static int returnInNestedTry(boolean b1) { + int a = 1; + try { + try { + if (b1) { + return 27; + } + } finally { + a = a * 3; + } + } finally { + a = a * 11; + } + return a; + } +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/Catch.java b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/Catch.java new file mode 100644 index 0000000..e6d91c1 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/Catch.java @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finallyblock.jack; + +public class Catch { + + public static void throwException() { + throw new RuntimeException(); + } + + public static void doNotThrowException() { + return; + } + + public static int tryCatchFinally1() { + int a = 1; + try { + a = a * 2; + throwException(); + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + } + return a; + } + + public static int tryCatchFinally2() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + } + return a; + } + + public static int shouldNotCatch1() { + int a = 1; + try { + try { + a = a * 2; + doNotThrowException(); + a = a * 3; + } catch (RuntimeException e) { + a = a * 5; + } finally { + a = a * 7; + throwException(); + a = a * 11; + } + } catch (RuntimeException e2) { + a = a * 13; + } + return a; + } + + public static int shouldNotCatch2() { + int a = 1; + try { + try { + a = a * 2; + doNotThrowException(); + a = a * 3; + } catch (RuntimeException e) { + try { + a = a * 5; + doNotThrowException(); + a = a * 17; + } catch (RuntimeException e2) { + a = a * 13; + } + } finally { + a = a * 7; + throwException(); + a = a * 11; + } + } catch (RuntimeException e2) { + a = a * 23; + } + return a; + } + + public static int finallyWithNew() { + Integer i = null; + try { + i = new Integer(1); + } + finally { + i = new Integer(2); + } + return (i.intValue()); + } + + public static int value = 0; + + @SuppressWarnings("finally") + public static int shouldNotCatch3() { + value = 0; + try { + try { + try { + return -1; + } catch (NullPointerException e) { + value += 5; + } + } + finally { + throw new NullPointerException(); + } + } catch (ArrayIndexOutOfBoundsException e) { + value += 3; + } + return value; + } +} diff --git a/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/EmptyBlocks.java b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/EmptyBlocks.java new file mode 100644 index 0000000..c20dde4 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/EmptyBlocks.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finallyblock.jack; + +public class EmptyBlocks { + + public static void throwException() { + throw new RuntimeException(); + } + + public static void doNotThrowException() { + return; + } + + public static int emptyTry() { + int a = 1; + try { + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + } + return a; + } + + public static int emptyCatch1() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 3; + } catch (Exception e) { + } finally { + a = a * 5; + } + return a; + } + + public static int emptyCatch2() { + int a = 1; + try { + a = a * 2; + throwException(); + a = a * 3; + } catch (Exception e) { + } finally { + a = a * 5; + } + return a; + } + + public static int emptyFinally1() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 3; + } catch (Exception e) { + a = a * 5; + } finally { + } + return a; + } + + public static int emptyFinally2() { + int a = 1; + try { + a = a * 2; + throwException(); + a = a * 3; + } catch (Exception e) { + a = a * 5; + } finally { + } + return a; + } + + public static int allEmpty() { + int a = 1; + try { + } catch (Exception e) { + } finally { + } + return a; + } +}
\ No newline at end of file diff --git a/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/Nested.java b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/Nested.java new file mode 100644 index 0000000..519f4d4 --- /dev/null +++ b/jack-tests/tests/com/android/jack/tryfinally/finallyblock/jack/Nested.java @@ -0,0 +1,633 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.tryfinally.finallyblock.jack; + +public class Nested { + + public static void throwException() { + throw new RuntimeException(); + } + + public static void doNotThrowException() { + return; + } + + public static int inTry1() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + try { + a = a * 7; + doNotThrowException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + } + a = a * 17; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + } + return a; + } + + public static int inTry2() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + try { + a = a * 7; + throwException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + } + a = a * 17; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + } + return a; + } + + public static int inTry3() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + try { + a = a * 7; + throwException(); + a = a * 19; + } finally { + a = a * 13; + } + a = a * 17; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + } + return a; + } + + public static int inTry4() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + try { + a = a * 7; + throwException(); + a = a * 29; + } catch (Exception e) { + a = a * 11; + throwException(); + a = a * 19; + } finally { + a = a * 13; + } + a = a * 17; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + } + return a; + } + + public static int inTry5() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + try { + a = a * 7; + doNotThrowException(); + a = a * 29; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + throwException(); + a = a * 19; + } + a = a * 17; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + } + return a; + } + + public static int inTry6() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + try { + a = a * 7; + throwException(); + a = a * 29; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + throwException(); + a = a * 19; + } + a = a * 17; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + } + return a; + } + + public static int inCatch1() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 19; + } catch (Exception e) { + a = a * 3; + try { + a = a * 7; + } catch (Exception e2) { + a = a * 11; + } finally { + a = a * 13; + } + a = a * 17; + } finally { + a = a * 5; + } + return a; + } + + public static int inCatch2() { + int a = 1; + try { + a = a * 2; + throwException(); + a = a * 19; + } catch (Exception e) { + a = a * 3; + try { + a = a * 7; + } catch (Exception e2) { + a = a * 11; + } finally { + a = a * 13; + } + a = a * 17; + } finally { + a = a * 5; + } + return a; + } + + public static int inCatch3() { + int a = 1; + try { + a = a * 2; + throwException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + try { + a = a * 7; + throwException(); + a = a * 19; + } catch (Exception e2) { + a = a * 11; + } finally { + a = a * 13; + } + a = a * 17; + } finally { + a = a * 5; + } + return a; + } + + public static int inCatch4() { + int a = 1; + try { + try { + a = a * 2; + throwException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + try { + a = a * 7; + throwException(); + a = a * 29; + } catch (Exception e2) { + a = a * 11; + throwException(); + a = a * 19; + } finally { + a = a * 13; + } + a = a * 17; + } finally { + a = a * 5; + } + } catch (Exception e3) { + a = a * 31; + } + return a; + } + + public static int inCatch5() { + int a = 1; + try { + try { + a = a * 2; + throwException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + try { + a = a * 7; + } catch (Exception e2) { + a = a * 11; + } finally { + a = a * 13; + throwException(); + a = a * 19; + } + a = a * 17; + } finally { + a = a * 5; + } + } catch (Exception e3) { + a = a * 31; + } + return a; + } + + public static int inCatch6() { + int a = 1; + try { + try { + a = a * 2; + throwException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + try { + a = a * 7; + throwException(); + a = a * 29; + } catch (Exception e2) { + a = a * 11; + } finally { + a = a * 13; + throwException(); + a = a * 19; + } + a = a * 17; + } finally { + a = a * 5; + } + } catch (Exception e3) { + a = a * 31; + } + return a; + } + + public static int inFinally1() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + try { + a = a * 7; + doNotThrowException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + } + a = a * 17; + } + return a; + } + + public static int inFinally2() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + try { + a = a * 7; + throwException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + } + a = a * 17; + } + return a; + } + + public static int inFinally3() { + int a = 1; + try { + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + try { + a = a * 7; + throwException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + throwException(); + a = a * 29; + } finally { + a = a * 13; + } + a = a * 17; + } + } catch (Exception e3) { + a = a * 31; + } + return a; + } + + public static int inFinally4() { + int a = 1; + try { + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + try { + a = a * 7; + doNotThrowException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + throwException(); + a = a * 29; + } + a = a * 17; + } + } catch (Exception e3) { + a = a * 31; + } + return a; + } + + public static int inFinally5() { + int a = 1; + try { + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + try { + a = a * 7; + throwException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + throwException(); + a = a * 29; + } + a = a * 17; + } + } catch (Exception e3) { + a = a * 31; + } + return a; + } + + public static int inFinally6() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + try { + a = a * 7; + doNotThrowException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + } + a = a * 17; + } + return a; + } + + public static int inFinally7() { + int a = 1; + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + try { + a = a * 7; + throwException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + } + a = a * 17; + } + return a; + } + + public static int inFinally8() { + int a = 1; + try { + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + try { + a = a * 7; + throwException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + throwException(); + a = a * 29; + } finally { + a = a * 13; + } + a = a * 17; + } + } catch (Exception e3) { + a = a * 31; + } + return a; + } + + public static int inFinally9() { + int a = 1; + try { + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + try { + a = a * 7; + doNotThrowException(); + a = a * 19; + } catch (Exception e) { + a = a * 11; + } finally { + a = a * 13; + throwException(); + a = a * 29; + } + a = a * 17; + } + } catch (Exception e3) { + a = a * 31; + } + return a; + } + + public static int inFinally10() { + int a = 1; + try { + try { + a = a * 2; + doNotThrowException(); + a = a * 23; + } catch (Exception e) { + a = a * 3; + } finally { + a = a * 5; + try { + a = a * 7; + throwException(); + a = a * 19; + } catch (Exception e2) { + a = a * 11; + } finally { + a = a * 13; + throwException(); + a = a * 29; + } + a = a * 17; + } + } catch (Exception e3) { + a = a * 31; + } + return a; + } + + public static int inFinally11() { + int result = 0; + try { + result += 1; + } finally { + result += 1; + try { + result += 1; + } finally { + try { + result += 1; + } finally { + result += 1; + try { + result += 1; + } finally { + result += 1; + } + } + } + } + return result; + } + +} |