View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   https://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.bcel.verifier.exc;
20  
21  import java.util.Arrays;
22  
23  /**
24   * Instances of this class should never be thrown. When such an instance is thrown, this is due to an INTERNAL ERROR of
25   * BCEL's class file verifier "JustIce".
26   */
27  public final class AssertionViolatedException extends RuntimeException {
28      private static final long serialVersionUID = -129822266349567409L;
29  
30      /**
31       * DO NOT USE. It's for experimental testing during development only.
32       */
33      public static void main(final String[] args) {
34          final AssertionViolatedException ave = new AssertionViolatedException(Arrays.toString(args));
35          ave.extendMessage("\nFOUND:\n\t", "\nExiting!!\n");
36          throw ave;
37      }
38  
39      /** The error message. */
40      private String detailMessage;
41  
42      /** Constructs a new AssertionViolatedException with null as its error message string. */
43      public AssertionViolatedException() {
44      }
45  
46      /**
47       * Constructs a new AssertionViolatedException with the specified error message preceded by "INTERNAL ERROR:
48       * ".
49       */
50      public AssertionViolatedException(String message) {
51          super(message = "INTERNAL ERROR: " + message); // Thanks to Java, the constructor call here must be first.
52          detailMessage = message;
53      }
54  
55      /**
56       * Constructs a new AssertionViolationException with the specified error message and initial cause
57       *
58       * @since 6.0
59       */
60      public AssertionViolatedException(String message, final Throwable initCause) {
61          super(message = "INTERNAL ERROR: " + message, initCause);
62          detailMessage = message;
63      }
64  
65      /**
66       * Extends the error message with a string before ("pre") and after ("post") the 'old' error message. All of these three
67       * strings are allowed to be null, and null is always replaced by the empty string (""). In particular, after invoking
68       * this method, the error message of this object can no longer be null.
69       */
70      public void extendMessage(String pre, String post) {
71          if (pre == null) {
72              pre = "";
73          }
74          if (detailMessage == null) {
75              detailMessage = "";
76          }
77          if (post == null) {
78              post = "";
79          }
80          detailMessage = pre + detailMessage + post;
81      }
82  
83      /**
84       * Returns the error message string of this AssertionViolatedException object.
85       *
86       * @return the error message string of this AssertionViolatedException.
87       */
88      @Override
89      public String getMessage() {
90          return detailMessage;
91      }
92  
93  }