001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 */ 018package org.apache.bcel.verifier; 019 020/** 021 * The NativeVerifier class implements a main(String[] args) method that's 022 * roughly compatible to the one in the Verifier class, but that uses the 023 * JVM's internal verifier for its class file verification. 024 * This can be used for comparison runs between the JVM-internal verifier 025 * and JustIce. 026 * 027 */ 028public abstract class NativeVerifier { 029 030 /** 031 * This class must not be instantiated. 032 */ 033 private NativeVerifier() { 034 } 035 036 037 /** 038 * Works only on the first argument. 039 */ 040 public static void main( final String[] args ) { 041 if (args.length != 1) { 042 System.out.println("Verifier front-end: need exactly one argument."); 043 System.exit(1); 044 } 045 final int dotclasspos = args[0].lastIndexOf(".class"); 046 if (dotclasspos != -1) { 047 args[0] = args[0].substring(0, dotclasspos); 048 } 049 args[0] = args[0].replace('/', '.'); 050 //System.out.println(args[0]); 051 try { 052 Class.forName(args[0]); 053 } catch (final ExceptionInInitializerError eiie) { //subclass of LinkageError! 054 System.out.println("NativeVerifier: ExceptionInInitializerError encountered on '" 055 + args[0] + "'."); 056 System.out.println(eiie); 057 System.exit(1); 058 } catch (final LinkageError le) { 059 System.out.println("NativeVerifier: LinkageError encountered on '" + args[0] + "'."); 060 System.out.println(le); 061 System.exit(1); 062 } catch (final ClassNotFoundException cnfe) { 063 System.out.println("NativeVerifier: FILE NOT FOUND: '" + args[0] + "'."); 064 System.exit(1); 065 } catch (final Throwable t) { // OK to catch Throwable here as we call exit. 066 System.out.println("NativeVerifier: Unspecified verification error on '" + args[0] + "'."); 067 System.exit(1); 068 } 069 System.out.println("NativeVerifier: Class file '" + args[0] + "' seems to be okay."); 070 System.exit(0); 071 } 072}