    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 */
    030public abstract class VerifierConstraintViolatedException extends RuntimeException{
    031    // /** The name of the offending class that did not pass the verifier. */
    032    // String name_of_offending_class;
    033
    034    private static final long serialVersionUID = 2946136970490179465L;
    035    /** The specified error message. */
    036    private String detailMessage;
    037    /**
    038     * Constructs a new VerifierConstraintViolatedException with null as its error message string.
    039     */
    040    VerifierConstraintViolatedException() {
    041        super();
    042    }
    043    /**
    044     * Constructs a new VerifierConstraintViolatedException with the specified error message.
    045     */
    046    VerifierConstraintViolatedException(final String message) {
    047        super(message); // Not that important
    048        detailMessage = message;
    049    }
    050    /**
    051     * Constructs a new VerifierConstraintViolationException with the specified error message and cause
    052     */
    053    VerifierConstraintViolatedException(final String message, final Throwable initCause) {
    054        super(message, initCause);
    055        detailMessage = message;
    056    }
    057
    058
    059    /** Extends the error message with a string before ("pre") and after ("post") the
    060        'old' error message. All of these three strings are allowed to be null, and null
    061        is always replaced by the empty string (""). In particular, after invoking this
    062        method, the error message of this object can no longer be null.
    063    */
    064    public void extendMessage(String pre, String post) {
    065        if (pre  == null) {
    066            pre="";
    067        }
    068        if (detailMessage == null) {
    069            detailMessage="";
    070        }
    071        if (post == null) {
    072            post="";
    073        }
    074        detailMessage = pre+detailMessage+post;
    075    }
    076    /**
    077     * Returns the error message string of this VerifierConstraintViolatedException object.
    078     * @return the error message string of this VerifierConstraintViolatedException.
    079     */
    080    @Override
    081    public String getMessage() {
    082        return detailMessage;
    083    }
    084}