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