blob: 678aef1f435c9aa2907d01df225c38d0653e3359 [file] [log] [blame]
Nicolas Geoffray4824c272015-06-24 15:53:03 +01001/*
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
17import java.lang.reflect.InvocationTargetException;
18import java.lang.reflect.Method;
19
20public class Main {
21 // Workaround for b/18051191.
22 class InnerClass {}
23
24 public static void main(String[] args) throws Exception {
Andreas Gampe52f205a2017-12-01 12:16:07 -080025 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
33 private static void checkLoad(String className, boolean expectError) throws Exception {
34 Class<?> c;
Nicolas Geoffray4824c272015-06-24 15:53:03 +010035 try {
Andreas Gampe52f205a2017-12-01 12:16:07 -080036 c = Class.forName(className);
37 if (expectError) {
38 throw new RuntimeException("Expected error for " + className);
Nicolas Geoffray4824c272015-06-24 15:53:03 +010039 }
Andreas Gampe52f205a2017-12-01 12:16:07 -080040 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);
Nicolas Geoffray4824c272015-06-24 15:53:03 +010055 }
56 }
57}