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 * @param args command line arguments.
34 */
35 public static void main(final String[] args) {
36 final AssertionViolatedException ave = new AssertionViolatedException(Arrays.toString(args));
37 ave.extendMessage("\nFOUND:\n\t", "\nExiting!!\n");
38 throw ave;
39 }
40
41 /** The error message. */
42 private String detailMessage;
43
44 /** Constructs a new AssertionViolatedException with null as its error message string. */
45 public AssertionViolatedException() {
46 }
47
48 /**
49 * Constructs a new AssertionViolatedException with the specified error message preceded by "INTERNAL ERROR:
50 * ".
51 *
52 * @param message the error message.
53 */
54 public AssertionViolatedException(String message) {
55 super(message = "INTERNAL ERROR: " + message); // Thanks to Java, the constructor call here must be first.
56 detailMessage = message;
57 }
58
59 /**
60 * Constructs a new AssertionViolationException with the specified error message and initial cause.
61 *
62 * @param message the error message.
63 * @param initCause the initial cause.
64 * @since 6.0
65 */
66 public AssertionViolatedException(String message, final Throwable initCause) {
67 super(message = "INTERNAL ERROR: " + message, initCause);
68 detailMessage = message;
69 }
70
71 /**
72 * Extends the error message with a string before ("pre") and after ("post") the 'old' error message. All of these three
73 * strings are allowed to be null, and null is always replaced by the empty string (""). In particular, after invoking
74 * this method, the error message of this object can no longer be null.
75 *
76 * @param pre string to prepend.
77 * @param post string to append.
78 */
79 public void extendMessage(String pre, String post) {
80 if (pre == null) {
81 pre = "";
82 }
83 if (detailMessage == null) {
84 detailMessage = "";
85 }
86 if (post == null) {
87 post = "";
88 }
89 detailMessage = pre + detailMessage + post;
90 }
91
92 /**
93 * Returns the error message string of this AssertionViolatedException object.
94 *
95 * @return the error message string of this AssertionViolatedException.
96 */
97 @Override
98 public String getMessage() {
99 return detailMessage;
100 }
101
102 }