1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 public class Main { $opt$bar()18 public static void $opt$bar() { 19 try { 20 $opt$foo(1); 21 } catch (NullPointerException e) { 22 $opt$foo(2); 23 } catch (RuntimeException e) { 24 $opt$foo(3); 25 } finally { 26 $opt$foo(4); 27 } 28 } 29 30 static int barState; 31 static int fooState; 32 main(String[] args)33 public static void main(String[] args) { 34 fooState = 0; 35 $opt$runTest(); 36 fooState = 1; 37 $opt$runTest(); 38 } 39 $opt$runTest()40 public static void $opt$runTest() { 41 barState = 1; 42 $opt$bar(); 43 barState = 2; 44 $opt$bar(); 45 barState = 3; 46 $opt$bar(); 47 barState = 4; 48 try { 49 $opt$bar(); 50 } catch (RuntimeException e) { 51 System.out.println("Caught " + e.getClass()); 52 } 53 } 54 $opt$foo(int value)55 public static void $opt$foo(int value) { 56 System.out.println(value); 57 if (value == barState) { 58 if (fooState == 0) { 59 throw new RuntimeException(); 60 } else { 61 throw new NullPointerException(); 62 } 63 } 64 } 65 } 66