xref: /aosp_15_r20/art/test/124-missing-classes/src/Main.java (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2011 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker public final class Main {
18*795d594fSAndroid Build Coastguard Worker 
main(String[] args)19*795d594fSAndroid Build Coastguard Worker     public static void main(String[] args) throws Exception {
20*795d594fSAndroid Build Coastguard Worker         System.out.println("Test Started");
21*795d594fSAndroid Build Coastguard Worker         testMissingFieldType();
22*795d594fSAndroid Build Coastguard Worker         testMissingMethodReturnType();
23*795d594fSAndroid Build Coastguard Worker         testMissingMethodParameterType();
24*795d594fSAndroid Build Coastguard Worker         testMissingInnerClass();
25*795d594fSAndroid Build Coastguard Worker         System.out.println("Test Finished");
26*795d594fSAndroid Build Coastguard Worker     }
27*795d594fSAndroid Build Coastguard Worker 
28*795d594fSAndroid Build Coastguard Worker     private static class ClassWithMissingFieldType {
29*795d594fSAndroid Build Coastguard Worker         MissingClass field;
30*795d594fSAndroid Build Coastguard Worker     }
31*795d594fSAndroid Build Coastguard Worker 
testMissingFieldType()32*795d594fSAndroid Build Coastguard Worker     private static void testMissingFieldType() throws Exception {
33*795d594fSAndroid Build Coastguard Worker         try {
34*795d594fSAndroid Build Coastguard Worker             ClassWithMissingFieldType.class.getDeclaredFields();
35*795d594fSAndroid Build Coastguard Worker             throw new AssertionError();
36*795d594fSAndroid Build Coastguard Worker         } catch (NoClassDefFoundError e) {
37*795d594fSAndroid Build Coastguard Worker             System.out.println("testMissingFieldType caught NoClassDefFoundError");
38*795d594fSAndroid Build Coastguard Worker         }
39*795d594fSAndroid Build Coastguard Worker     }
40*795d594fSAndroid Build Coastguard Worker 
41*795d594fSAndroid Build Coastguard Worker     private static class ClassWithMissingMethodReturnType {
method()42*795d594fSAndroid Build Coastguard Worker         MissingClass method() {
43*795d594fSAndroid Build Coastguard Worker             return null;
44*795d594fSAndroid Build Coastguard Worker         }
45*795d594fSAndroid Build Coastguard Worker     }
46*795d594fSAndroid Build Coastguard Worker 
testMissingMethodReturnType()47*795d594fSAndroid Build Coastguard Worker     private static void testMissingMethodReturnType() throws Exception {
48*795d594fSAndroid Build Coastguard Worker         try {
49*795d594fSAndroid Build Coastguard Worker             ClassWithMissingMethodReturnType.class.getDeclaredMethods();
50*795d594fSAndroid Build Coastguard Worker             throw new AssertionError();
51*795d594fSAndroid Build Coastguard Worker         } catch (NoClassDefFoundError e) {
52*795d594fSAndroid Build Coastguard Worker             System.out.println("testMissingMethodReturnType caught NoClassDefFoundError");
53*795d594fSAndroid Build Coastguard Worker         }
54*795d594fSAndroid Build Coastguard Worker     }
55*795d594fSAndroid Build Coastguard Worker 
56*795d594fSAndroid Build Coastguard Worker     private static class ClassWithMissingMethodParameterType {
method(MissingClass arg)57*795d594fSAndroid Build Coastguard Worker         void method(MissingClass arg) {}
58*795d594fSAndroid Build Coastguard Worker     }
59*795d594fSAndroid Build Coastguard Worker 
testMissingMethodParameterType()60*795d594fSAndroid Build Coastguard Worker     private static void testMissingMethodParameterType() throws Exception {
61*795d594fSAndroid Build Coastguard Worker         try {
62*795d594fSAndroid Build Coastguard Worker             ClassWithMissingMethodParameterType.class.getDeclaredMethods();
63*795d594fSAndroid Build Coastguard Worker             throw new AssertionError();
64*795d594fSAndroid Build Coastguard Worker         } catch (NoClassDefFoundError e) {
65*795d594fSAndroid Build Coastguard Worker             System.out.println("testMissingMethodParameterType caught NoClassDefFoundError");
66*795d594fSAndroid Build Coastguard Worker         }
67*795d594fSAndroid Build Coastguard Worker     }
68*795d594fSAndroid Build Coastguard Worker 
69*795d594fSAndroid Build Coastguard Worker     private static final class MissingInnerClass {
70*795d594fSAndroid Build Coastguard Worker     }
71*795d594fSAndroid Build Coastguard Worker 
testMissingInnerClass()72*795d594fSAndroid Build Coastguard Worker     private static void testMissingInnerClass() throws Exception {
73*795d594fSAndroid Build Coastguard Worker         try {
74*795d594fSAndroid Build Coastguard Worker             Main.class.getDeclaredClasses();
75*795d594fSAndroid Build Coastguard Worker             throw new AssertionError();
76*795d594fSAndroid Build Coastguard Worker         } catch (NoClassDefFoundError e) {
77*795d594fSAndroid Build Coastguard Worker             System.out.println("testMissingInnerClass caught NoClassDefFoundError");
78*795d594fSAndroid Build Coastguard Worker         }
79*795d594fSAndroid Build Coastguard Worker     }
80*795d594fSAndroid Build Coastguard Worker }
81