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