AssertionViolatedException.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  *  Unless required by applicable law or agreed to in writing, software
  12.  *  distributed under the License is distributed on an "AS IS" BASIS,
  13.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  *  See the License for the specific language governing permissions and
  15.  *  limitations under the License.
  16.  */
  17. package org.apache.bcel.verifier.exc;

  18. import java.util.Arrays;

  19. /**
  20.  * Instances of this class should never be thrown. When such an instance is thrown, this is due to an INTERNAL ERROR of
  21.  * BCEL's class file verifier "JustIce".
  22.  */
  23. public final class AssertionViolatedException extends RuntimeException {
  24.     private static final long serialVersionUID = -129822266349567409L;

  25.     /**
  26.      * DO NOT USE. It's for experimental testing during development only.
  27.      */
  28.     public static void main(final String[] args) {
  29.         final AssertionViolatedException ave = new AssertionViolatedException(Arrays.toString(args));
  30.         ave.extendMessage("\nFOUND:\n\t", "\nExiting!!\n");
  31.         throw ave;
  32.     }

  33.     /** The error message. */
  34.     private String detailMessage;

  35.     /** Constructs a new AssertionViolatedException with null as its error message string. */
  36.     public AssertionViolatedException() {
  37.     }

  38.     /**
  39.      * Constructs a new AssertionViolatedException with the specified error message preceded by "INTERNAL ERROR:
  40.      * ".
  41.      */
  42.     public AssertionViolatedException(String message) {
  43.         super(message = "INTERNAL ERROR: " + message); // Thanks to Java, the constructor call here must be first.
  44.         detailMessage = message;
  45.     }

  46.     /**
  47.      * Constructs a new AssertionViolationException with the specified error message and initial cause
  48.      *
  49.      * @since 6.0
  50.      */
  51.     public AssertionViolatedException(String message, final Throwable initCause) {
  52.         super(message = "INTERNAL ERROR: " + message, initCause);
  53.         detailMessage = message;
  54.     }

  55.     /**
  56.      * Extends the error message with a string before ("pre") and after ("post") the 'old' error message. All of these three
  57.      * strings are allowed to be null, and null is always replaced by the empty string (""). In particular, after invoking
  58.      * this method, the error message of this object can no longer be null.
  59.      */
  60.     public void extendMessage(String pre, String post) {
  61.         if (pre == null) {
  62.             pre = "";
  63.         }
  64.         if (detailMessage == null) {
  65.             detailMessage = "";
  66.         }
  67.         if (post == null) {
  68.             post = "";
  69.         }
  70.         detailMessage = pre + detailMessage + post;
  71.     }

  72.     /**
  73.      * Returns the error message string of this AssertionViolatedException object.
  74.      *
  75.      * @return the error message string of this AssertionViolatedException.
  76.      */
  77.     @Override
  78.     public String getMessage() {
  79.         return detailMessage;
  80.     }

  81. }