View Javadoc
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   */
18  package org.apache.bcel.verifier.exc;
19  
20  
21  /**
22   * Instances of this class should never be thrown. When such an instance is thrown,
23   * this is due to an INTERNAL ERROR of BCEL's class file verifier "JustIce".
24   *
25   * @version $Id: AssertionViolatedException.html 1018313 2017-09-18 09:03:04Z britter $
26   */
27  public final class AssertionViolatedException extends RuntimeException{
28      private static final long serialVersionUID = -129822266349567409L;
29      /** The error message. */
30      private String detailMessage;
31      /** Constructs a new AssertionViolatedException with null as its error message string. */
32      public AssertionViolatedException() {
33          super();
34      }
35      /**
36       * Constructs a new AssertionViolatedException with the specified error message preceded
37       * by "INTERNAL ERROR: ".
38       */
39      public AssertionViolatedException(String message) {
40          super(message = "INTERNAL ERROR: "+message); // Thanks to Java, the constructor call here must be first.
41          detailMessage=message;
42      }
43      /**
44       * Constructs a new AssertionViolationException with the specified error message and initial cause
45       * @since 6.0
46       */
47      public AssertionViolatedException(String message, final Throwable initCause) {
48          super(message = "INTERNAL ERROR: "+message, initCause);
49          detailMessage=message;
50      }
51      /** Extends the error message with a string before ("pre") and after ("post") the
52          'old' error message. All of these three strings are allowed to be null, and null
53          is always replaced by the empty string (""). In particular, after invoking this
54          method, the error message of this object can no longer be null.
55      */
56      public void extendMessage(String pre, String post) {
57          if (pre  == null) {
58              pre="";
59          }
60          if (detailMessage == null) {
61              detailMessage="";
62          }
63          if (post == null) {
64              post="";
65          }
66          detailMessage = pre+detailMessage+post;
67      }
68      /**
69       * Returns the error message string of this AssertionViolatedException object.
70       * @return the error message string of this AssertionViolatedException.
71       */
72      @Override
73      public String getMessage() {
74          return detailMessage;
75      }
76  
77      /**
78       * DO NOT USE. It's for experimental testing during development only.
79       */
80      public static void main(final String[] args) {
81          final AssertionViolatedException ave = new AssertionViolatedException("Oops!");
82          ave.extendMessage("\nFOUND:\n\t","\nExiting!!\n");
83          throw ave;
84      }
85  
86  }