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      /** The specified error message. */
32      private String detailMessage;
33  
34      /**
35       * Constructs a new VerifierConstraintViolatedException with null as its error message string.
36       */
37      VerifierConstraintViolatedException() {
38      }
39  
40      /**
41       * Constructs a new VerifierConstraintViolatedException with the specified error message.
42       */
43      VerifierConstraintViolatedException(final String message) {
44          super(message); // Not that important
45          detailMessage = message;
46      }
47  
48      /**
49       * Constructs a new VerifierConstraintViolationException with the specified error message and cause
50       */
51      VerifierConstraintViolatedException(final String message, final Throwable initCause) {
52          super(message, initCause);
53          detailMessage = message;
54      }
55  
56      /**
57       * Extends the error message with a string before ("pre") and after ("post") the 'old' error message. All of these three
58       * strings are allowed to be null, and null is always replaced by the empty string (""). In particular, after invoking
59       * this method, the error message of this object can no longer be null.
60       */
61      public void extendMessage(String pre, String post) {
62          if (pre == null) {
63              pre = "";
64          }
65          if (detailMessage == null) {
66              detailMessage = "";
67          }
68          if (post == null) {
69              post = "";
70          }
71          detailMessage = pre + detailMessage + post;
72      }
73  
74      /**
75       * Returns the error message string of this VerifierConstraintViolatedException object.
76       *
77       * @return the error message string of this VerifierConstraintViolatedException.
78       */
79      @Override
80      public String getMessage() {
81          return detailMessage;
82      }
83  }