Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2017 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     public static void main(String[] args) {
     22         try {
     23             // Make sure that the abstract final class is marked as erroneous.
     24             Class.forName("AbstractFinal");
     25             System.out.println("UNREACHABLE!");
     26         } catch (VerifyError expected) {
     27         } catch (Throwable t) {
     28             t.printStackTrace(System.out);
     29         }
     30         try {
     31             // Verification of TestClass.test() used to crash when processing
     32             // the final abstract (erroneous) class.
     33             Class<?> tc = Class.forName("TestClass");
     34             Method test = tc.getDeclaredMethod("test");
     35             test.invoke(null);
     36             System.out.println("UNREACHABLE!");
     37         } catch (InvocationTargetException ite) {
     38             if (ite.getCause() instanceof InstantiationError) {
     39                 System.out.println(
     40                     ite.getCause().getClass().getName() + ": " + ite.getCause().getMessage());
     41             } else {
     42                 ite.printStackTrace(System.out);
     43             }
     44         } catch (Throwable t) {
     45             t.printStackTrace(System.out);
     46         }
     47     }
     48 }
     49