1 /*
2  * Copyright (C) 2011 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 final class Main {
18 
main(String[] args)19     public static void main(String[] args) throws Exception {
20         System.out.println("Test Started");
21         testMissingFieldType();
22         testMissingMethodReturnType();
23         testMissingMethodParameterType();
24         testMissingInnerClass();
25         System.out.println("Test Finished");
26     }
27 
28     private static class ClassWithMissingFieldType {
29         MissingClass field;
30     }
31 
testMissingFieldType()32     private static void testMissingFieldType() throws Exception {
33         try {
34             ClassWithMissingFieldType.class.getDeclaredFields();
35             throw new AssertionError();
36         } catch (NoClassDefFoundError e) {
37             System.out.println("testMissingFieldType caught NoClassDefFoundError");
38         }
39     }
40 
41     private static class ClassWithMissingMethodReturnType {
method()42         MissingClass method() {
43             return null;
44         }
45     }
46 
testMissingMethodReturnType()47     private static void testMissingMethodReturnType() throws Exception {
48         try {
49             ClassWithMissingMethodReturnType.class.getDeclaredMethods();
50             throw new AssertionError();
51         } catch (NoClassDefFoundError e) {
52             System.out.println("testMissingMethodReturnType caught NoClassDefFoundError");
53         }
54     }
55 
56     private static class ClassWithMissingMethodParameterType {
method(MissingClass arg)57         void method(MissingClass arg) {}
58     }
59 
testMissingMethodParameterType()60     private static void testMissingMethodParameterType() throws Exception {
61         try {
62             ClassWithMissingMethodParameterType.class.getDeclaredMethods();
63             throw new AssertionError();
64         } catch (NoClassDefFoundError e) {
65             System.out.println("testMissingMethodParameterType caught NoClassDefFoundError");
66         }
67     }
68 
69     private static final class MissingInnerClass {
70     }
71 
testMissingInnerClass()72     private static void testMissingInnerClass() throws Exception {
73         try {
74             Main.class.getDeclaredClasses();
75             throw new AssertionError();
76         } catch (NoClassDefFoundError e) {
77             System.out.println("testMissingInnerClass caught NoClassDefFoundError");
78         }
79     }
80 }
81