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  /**
22   * Instances of this class are thrown by BCEL's class file verifier "JustIce" whenever verification proves that some
23   * constraint of a class file (as stated in the Java Virtual Machine Specification, Edition 2) is violated. This is
24   * roughly equivalent to the VerifyError the JVM-internal verifiers throw.
25   */
26  public abstract class VerifierConstraintViolatedException extends RuntimeException {
27      // /** The name of the offending class that did not pass the verifier. */
28      // String name_of_offending_class;
29  
30      private static final long serialVersionUID = 2946136970490179465L;
31  
32      /** The specified error message. */
33      private String detailMessage;
34  
35      /**
36       * Constructs a new VerifierConstraintViolatedException with null as its error message string.
37       */
38      VerifierConstraintViolatedException() {
39      }
40  
41      /**
42       * Constructs a new VerifierConstraintViolatedException with the specified error message.
43       */
44      VerifierConstraintViolatedException(final String message) {
45          super(message); // Not that important
46          detailMessage = message;
47      }
48  
49      /**
50       * Constructs a new VerifierConstraintViolationException with the specified error message and cause
51       */
52      VerifierConstraintViolatedException(final String message, final Throwable initCause) {
53          super(message, initCause);
54          detailMessage = message;
55      }
56  
57      /**
58       * Extends the error message with a string before ("pre") and after ("post") the 'old' error message. All of these three
59       * strings are allowed to be null, and null is always replaced by the empty string (""). In particular, after invoking
60       * this method, the error message of this object can no longer be null.
61       *
62       * @param pre string to prepend.
63       * @param post string to append.
64       */
65      public void extendMessage(String pre, String post) {
66          if (pre == null) {
67              pre = "";
68          }
69          if (detailMessage == null) {
70              detailMessage = "";
71          }
72          if (post == null) {
73              post = "";
74          }
75          detailMessage = pre + detailMessage + post;
76      }
77  
78      /**
79       * Returns the error message string of this VerifierConstraintViolatedException object.
80       *
81       * @return the error message string of this VerifierConstraintViolatedException.
82       */
83      @Override
84      public String getMessage() {
85          return detailMessage;
86      }
87  }