• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 import java.lang.reflect.InvocationTargetException;
18 import java.lang.reflect.Method;
19 
20 public class Main {
21   // Workaround for b/18051191.
22   class InnerClass {}
23 
main(String[] args)24   public static void main(String[] args) throws Exception {
25     checkLoad("NullArrayFailInt2Object", true);
26     checkLoad("NullArrayFailObject2Int", true);
27     checkLoad("NullArraySuccessInt", false);
28     checkLoad("NullArraySuccessInt2Float", false);
29     checkLoad("NullArraySuccessShort", false);
30     checkLoad("NullArraySuccessRef", false);
31   }
32 
checkLoad(String className, boolean expectError)33   private static void checkLoad(String className, boolean expectError) throws Exception {
34     Class<?> c;
35     try {
36       c = Class.forName(className);
37       if (expectError) {
38         throw new RuntimeException("Expected error for " + className);
39       }
40       Method m = c.getMethod("method");
41       try {
42         m.invoke(null);
43         throw new RuntimeException("Expected an InvocationTargetException");
44       } catch (InvocationTargetException e) {
45         if (!(e.getCause() instanceof NullPointerException)) {
46           throw new RuntimeException("Expected a NullPointerException");
47         }
48         System.out.println(className);
49       }
50     } catch (VerifyError e) {
51       if (!expectError) {
52         throw new RuntimeException(e);
53       }
54       System.out.println(className);
55     }
56   }
57 }
58