View Javadoc
1 package org.apache.bcel.verifier; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache BCEL" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache BCEL", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 import java.util.ArrayList; 58 59 /*** 60 * A PassVerifier actually verifies a class file; it is instantiated 61 * by a Verifier. 62 * The verification should conform with a certain pass as described 63 * in The Java Virtual Machine Specification, 2nd edition. 64 * This book describes four passes. Pass one means loading the 65 * class and verifying a few static constraints. Pass two actually 66 * verifies some other constraints that could enforce loading in 67 * referenced class files. Pass three is the first pass that actually 68 * checks constraints in the code array of a method in the class file; 69 * it has two parts with the first verifying static constraints and 70 * the second part verifying structural constraints (where a data flow 71 * analysis is used for). The fourth pass, finally, performs checks 72 * that can only be done at run-time. 73 * JustIce does not have a run-time pass, but certain constraints that 74 * are usually delayed until run-time for performance reasons are also 75 * checked during the second part of pass three. 76 * PassVerifier instances perform caching. 77 * That means, if you really want a new verification run of a certain 78 * pass you must use a new instance of a given PassVerifier. 79 * 80 * @version $Id: PassVerifier.java,v 1.1.1.1 2001/10/29 20:00:31 jvanzyl Exp $ 81 * @author <A HREF="http://www.inf.fu-berlin.de/~ehaase"/>Enver Haase</A> 82 * @see org.apache.bcel.verifier.Verifier 83 * @see #verify() 84 */ 85 public abstract class PassVerifier{ 86 87 /*** The (warning) messages. */ 88 private ArrayList messages = new ArrayList(); //Type of elements: String 89 90 /*** The VerificationResult cache. */ 91 private VerificationResult verificationResult = null; 92 93 /*** 94 * This method runs a verification pass conforming to the 95 * Java Virtual Machine Specification, 2nd edition, on a 96 * class file. 97 * PassVerifier instances perform caching; 98 * i.e. if the verify() method once determined a VerificationResult, 99 * then this result may be returned after every invocation of this 100 * method instead of running the verification pass anew; likewise with 101 * the result of getMessages(). 102 * 103 * @see #getMessages() 104 * @see #addMessage(String) 105 */ 106 public VerificationResult verify(){ 107 if (verificationResult == null){ 108 verificationResult = do_verify(); 109 } 110 return verificationResult; 111 } 112 113 /*** Does the real verification work, uncached. */ 114 public abstract VerificationResult do_verify(); 115 116 /*** 117 * This method adds a (warning) message to the message pool of this 118 * PassVerifier. This method is normally only internally used by 119 * BCEL's class file verifier "JustIce" and should not be used from 120 * the outside. 121 * 122 * @see #getMessages() 123 */ 124 public void addMessage(String message){ 125 messages.add(message); 126 } 127 128 /*** 129 * Returns the (warning) messages that this PassVerifier accumulated 130 * during its do_verify()ing work. 131 * 132 * @see #addMessage(String) 133 * @see #do_verify() 134 */ 135 public String[] getMessages(){ 136 verify(); // create messages if not already done (cached!) 137 String[] ret = new String[messages.size()]; 138 for (int i=0; i<messages.size(); i++){ 139 ret[i] = (String) messages.get(i); 140 } 141 return ret; 142 } 143 }

This page was automatically generated by Maven