NativeVerifier xref

View Javadoc

    1   /*
    2    * Copyright  2000-2004 The Apache Software Foundation
    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  package org.apache.bcel.verifier;
    18
    19  /***
    20   * The NativeVerifier class implements a main(String[] args) method that's
    21   * roughly compatible to the one in the Verifier class, but that uses the
    22   * JVM's internal verifier for its class file verification.
    23   * This can be used for comparison runs between the JVM-internal verifier
    24   * and JustIce.
    25   *
    26   * @version $Id: NativeVerifier.java 386056 2006-03-15 11:31:56Z tcurdt $
    27   * @author Enver Haase
    28   */
    29  public abstract class NativeVerifier {
    30
    31      /***
    32       * This class must not be instantiated.
    33       */
    34      private NativeVerifier() {
    35      }
    36
    37
    38      /***
    39       * Works only on the first argument.
    40       */
    41      public static void main( String[] args ) {
    42          if (args.length != 1) {
    43              System.out.println("Verifier front-end: need exactly one argument.");
    44              System.exit(1);
    45          }
    46          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 (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 (LinkageError le) {
    60              System.out.println("NativeVerifier: LinkageError encountered on '" + args[0] + "'.");
    61              System.out.println(le);
    62              System.exit(1);
    63          } catch (ClassNotFoundException cnfe) {
    64              System.out.println("NativeVerifier: FILE NOT FOUND: '" + args[0] + "'.");
    65              System.exit(1);
    66          } catch (Throwable t) {
    67              System.out.println("NativeVerifier: Unspecified verification error on'" + args[0]
    68                      + "'.");
    69              System.exit(1);
    70          }
    71          System.out.println("NativeVerifier: Class file '" + args[0] + "' seems to be okay.");
    72          System.exit(0);
    73      }
    74  }