    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.exc;
    019
    020
    021/**
    022 * Instances of this class are thrown by BCEL's class file verifier "JustIce"
    023 * whenever
    024 * verification proves that some constraint of a class file (as stated in the
    025 * Java Virtual Machine Specification, Edition 2) is violated.
    026 * This is roughly equivalent to the VerifyError the JVM-internal verifiers
    027 * throw.
    028 *
    029 * @version $Id$
    030 */
    031public abstract class VerifierConstraintViolatedException extends RuntimeException{
    032    // /** The name of the offending class that did not pass the verifier. */
    033    // String name_of_offending_class;
    034
    035    private static final long serialVersionUID = 2946136970490179465L;
    036    /** The specified error message. */
    037    private String detailMessage;
    038    /**
    039     * Constructs a new VerifierConstraintViolatedException with null as its error message string.
    040     */
    041    VerifierConstraintViolatedException() {
    042        super();
    043    }
    044    /**
    045     * Constructs a new VerifierConstraintViolatedException with the specified error message.
    046     */
    047    VerifierConstraintViolatedException(final String message) {
    048        super(message); // Not that important
    049        detailMessage = message;
    050    }
    051    /**
    052     * Constructs a new VerifierConstraintViolationException with the specified error message and cause
    053     */
    054    VerifierConstraintViolatedException(final String message, final Throwable initCause) {
    055        super(message, initCause);
    056        detailMessage = message;
    057    }
    058
    059
    060    /** Extends the error message with a string before ("pre") and after ("post") the
    061        'old' error message. All of these three strings are allowed to be null, and null
    062        is always replaced by the empty string (""). In particular, after invoking this
    063        method, the error message of this object can no longer be null.
    064    */
    065    public void extendMessage(String pre, String post) {
    066        if (pre  == null) {
    067            pre="";
    068        }
    069        if (detailMessage == null) {
    070            detailMessage="";
    071        }
    072        if (post == null) {
    073            post="";
    074        }
    075        detailMessage = pre+detailMessage+post;
    076    }
    077    /**
    078     * Returns the error message string of this VerifierConstraintViolatedException object.
    079     * @return the error message string of this VerifierConstraintViolatedException.
    080     */
    081    @Override
    082    public String getMessage() {
    083        return detailMessage;
    084    }
    085}