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