1 /* 2 * Copyright (C) 2009 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 { 18 static class ArrayObj { 19 int[] array; 20 getArrayElement(int i)21 int getArrayElement(int i) throws NullPointerException { 22 return array[i]; 23 } 24 } 25 main(String[] args)26 public static void main(String[] args) { 27 ArrayObj arrayObj2 = new ArrayObj(); 28 int sum = 0; 29 int exception = 0; 30 31 for (int i = 0; i < 1024; i++) { 32 try { 33 // A hot method invocation that always encounters exceptions 34 sum += arrayObj2.getArrayElement(i); 35 } catch (NullPointerException npe) { 36 exception++; 37 } 38 } 39 System.out.println("sum = " + sum); 40 System.out.println("exception = " + exception); 41 } 42 } 43