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