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 * @version $Id: NativeVerifier.java 1749603 2016-06-21 20:50:19Z ggregory $ 028 */ 029public abstract class NativeVerifier { 030 031 /** 032 * This class must not be instantiated. 033 */ 034 private NativeVerifier() { 035 } 036 037 038 /** 039 * Works only on the first argument. 040 */ 041 public static void main( final String[] args ) { 042 if (args.length != 1) { 043 System.out.println("Verifier front-end: need exactly one argument."); 044 System.exit(1); 045 } 046 final int dotclasspos = args[0].lastIndexOf(".class"); 047 if (dotclasspos != -1) { 048 args[0] = args[0].substring(0, dotclasspos); 049 } 050 args[0] = args[0].replace('/', '.'); 051 //System.out.println(args[0]); 052 try { 053 Class.forName(args[0]); 054 } catch (final ExceptionInInitializerError eiie) { //subclass of LinkageError! 055 System.out.println("NativeVerifier: ExceptionInInitializerError encountered on '" 056 + args[0] + "'."); 057 System.out.println(eiie); 058 System.exit(1); 059 } catch (final LinkageError le) { 060 System.out.println("NativeVerifier: LinkageError encountered on '" + args[0] + "'."); 061 System.out.println(le); 062 System.exit(1); 063 } catch (final ClassNotFoundException cnfe) { 064 System.out.println("NativeVerifier: FILE NOT FOUND: '" + args[0] + "'."); 065 System.exit(1); 066 } catch (final Throwable t) { // OK to catch Throwable here as we call exit. 067 System.out.println("NativeVerifier: Unspecified verification error on '" + args[0] + "'."); 068 System.exit(1); 069 } 070 System.out.println("NativeVerifier: Class file '" + args[0] + "' seems to be okay."); 071 System.exit(0); 072 } 073}