1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 package org.apache.bcel.verifier; 19 20 /** 21 * The NativeVerifier class implements a main(String[] args) method that's 22 * roughly compatible to the one in the Verifier class, but that uses the 23 * JVM's internal verifier for its class file verification. 24 * This can be used for comparison runs between the JVM-internal verifier 25 * and JustIce. 26 * 27 * @version $Id$ 28 */ 29 public abstract class NativeVerifier { 30 31 /** 32 * This class must not be instantiated. 33 */ NativeVerifier()34 private NativeVerifier() { 35 } 36 37 38 /** 39 * Works only on the first argument. 40 */ main( final String[] args )41 public static void main( final String[] args ) { 42 if (args.length != 1) { 43 System.out.println("Verifier front-end: need exactly one argument."); 44 System.exit(1); 45 } 46 final int dotclasspos = args[0].lastIndexOf(".class"); 47 if (dotclasspos != -1) { 48 args[0] = args[0].substring(0, dotclasspos); 49 } 50 args[0] = args[0].replace('/', '.'); 51 //System.out.println(args[0]); 52 try { 53 Class.forName(args[0]); 54 } catch (final ExceptionInInitializerError eiie) { //subclass of LinkageError! 55 System.out.println("NativeVerifier: ExceptionInInitializerError encountered on '" 56 + args[0] + "'."); 57 System.out.println(eiie); 58 System.exit(1); 59 } catch (final LinkageError le) { 60 System.out.println("NativeVerifier: LinkageError encountered on '" + args[0] + "'."); 61 System.out.println(le); 62 System.exit(1); 63 } catch (final ClassNotFoundException cnfe) { 64 System.out.println("NativeVerifier: FILE NOT FOUND: '" + args[0] + "'."); 65 System.exit(1); 66 } catch (final Throwable t) { // OK to catch Throwable here as we call exit. 67 System.out.println("NativeVerifier: Unspecified verification error on '" + args[0] + "'."); 68 System.exit(1); 69 } 70 System.out.println("NativeVerifier: Class file '" + args[0] + "' seems to be okay."); 71 System.exit(0); 72 } 73 } 74