    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
    020import java.util.Arrays;
    021
    022/**
    023 * Instances of this class should never be thrown. When such an instance is thrown, this is due to an INTERNAL ERROR of
    024 * BCEL's class file verifier &quot;JustIce&quot;.
    025 *
    026 */
    027public final class AssertionViolatedException extends RuntimeException {
    028    private static final long serialVersionUID = -129822266349567409L;
    029
    030    /**
    031     * DO NOT USE. It's for experimental testing during development only.
    032     */
    033    public static void main(final String[] args) {
    034        final AssertionViolatedException ave = new AssertionViolatedException(Arrays.toString(args));
    035        ave.extendMessage("\nFOUND:\n\t", "\nExiting!!\n");
    036        throw ave;
    037    }
    038
    039    /** The error message. */
    040    private String detailMessage;
    041
    042    /** Constructs a new AssertionViolatedException with null as its error message string. */
    043    public AssertionViolatedException() {
    044    }
    045
    046    /**
    047     * Constructs a new AssertionViolatedException with the specified error message preceded by &quot;INTERNAL ERROR:
    048     * &quot;.
    049     */
    050    public AssertionViolatedException(String message) {
    051        super(message = "INTERNAL ERROR: " + message); // Thanks to Java, the constructor call here must be first.
    052        detailMessage = message;
    053    }
    054
    055    /**
    056     * Constructs a new AssertionViolationException with the specified error message and initial cause
    057     *
    058     * @since 6.0
    059     */
    060    public AssertionViolatedException(String message, final Throwable initCause) {
    061        super(message = "INTERNAL ERROR: " + message, initCause);
    062        detailMessage = message;
    063    }
    064
    065    /**
    066     * Extends the error message with a string before ("pre") and after ("post") the 'old' error message. All of these three
    067     * strings are allowed to be null, and null is always replaced by the empty string (""). In particular, after invoking
    068     * this method, the error message of this object can no longer be null.
    069     */
    070    public void extendMessage(String pre, String post) {
    071        if (pre == null) {
    072            pre = "";
    073        }
    074        if (detailMessage == null) {
    075            detailMessage = "";
    076        }
    077        if (post == null) {
    078            post = "";
    079        }
    080        detailMessage = pre + detailMessage + post;
    081    }
    082
    083    /**
    084     * Returns the error message string of this AssertionViolatedException object.
    085     *
    086     * @return the error message string of this AssertionViolatedException.
    087     */
    088    @Override
    089    public String getMessage() {
    090        return detailMessage;
    091    }
    092
    093}