blob: 7090194d327eec0639a7c50a756d4a6d3a5f7e27 [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 {
Nicolas Geoffray4824c272015-06-24 15:53:03 +010021 public static void main(String[] args) throws Exception {
Andreas Gampe52f205a2017-12-01 12:16:07 -080022 checkLoad("NullArrayFailInt2Object", true);
23 checkLoad("NullArrayFailObject2Int", true);
24 checkLoad("NullArraySuccessInt", false);
25 checkLoad("NullArraySuccessInt2Float", false);
26 checkLoad("NullArraySuccessShort", false);
27 checkLoad("NullArraySuccessRef", false);
28 }
29
30 private static void checkLoad(String className, boolean expectError) throws Exception {
31 Class<?> c;
Nicolas Geoffray4824c272015-06-24 15:53:03 +010032 try {
Andreas Gampe52f205a2017-12-01 12:16:07 -080033 c = Class.forName(className);
34 if (expectError) {
35 throw new RuntimeException("Expected error for " + className);
Nicolas Geoffray4824c272015-06-24 15:53:03 +010036 }
Andreas Gampe52f205a2017-12-01 12:16:07 -080037 Method m = c.getMethod("method");
38 try {
39 m.invoke(null);
40 throw new RuntimeException("Expected an InvocationTargetException");
41 } catch (InvocationTargetException e) {
42 if (!(e.getCause() instanceof NullPointerException)) {
43 throw new RuntimeException("Expected a NullPointerException");
44 }
45 System.out.println(className);
46 }
47 } catch (VerifyError e) {
48 if (!expectError) {
49 throw new RuntimeException(e);
50 }
51 System.out.println(className);
Nicolas Geoffray4824c272015-06-24 15:53:03 +010052 }
53 }
54}