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: NativeVerifier.java 947879 2010-05-25 00:48:30Z sebb $
28 * @author Enver Haase
29 */
30 public abstract class NativeVerifier {
31
32 /**
33 * This class must not be instantiated.
34 */
35 private NativeVerifier() {
36 }
37
38
39 /**
40 * Works only on the first argument.
41 */
42 public static void main( String[] args ) {
43 if (args.length != 1) {
44 System.out.println("Verifier front-end: need exactly one argument.");
45 System.exit(1);
46 }
47 int dotclasspos = args[0].lastIndexOf(".class");
48 if (dotclasspos != -1) {
49 args[0] = args[0].substring(0, dotclasspos);
50 }
51 args[0] = args[0].replace('/', '.');
52 //System.out.println(args[0]);
53 try {
54 Class.forName(args[0]);
55 } catch (ExceptionInInitializerError eiie) { //subclass of LinkageError!
56 System.out.println("NativeVerifier: ExceptionInInitializerError encountered on '"
57 + args[0] + "'.");
58 System.out.println(eiie);
59 System.exit(1);
60 } catch (LinkageError le) {
61 System.out.println("NativeVerifier: LinkageError encountered on '" + args[0] + "'.");
62 System.out.println(le);
63 System.exit(1);
64 } catch (ClassNotFoundException cnfe) {
65 System.out.println("NativeVerifier: FILE NOT FOUND: '" + args[0] + "'.");
66 System.exit(1);
67 } catch (Throwable t) {
68 System.out.println("NativeVerifier: Unspecified verification error on'" + args[0]
69 + "'.");
70 System.exit(1);
71 }
72 System.out.println("NativeVerifier: Class file '" + args[0] + "' seems to be okay.");
73 System.exit(0);
74 }
75 }