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