VerifierConstraintViolatedException.java

  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.  * Instances of this class are thrown by BCEL's class file verifier "JustIce" whenever verification proves that some
  20.  * constraint of a class file (as stated in the Java Virtual Machine Specification, Edition 2) is violated. This is
  21.  * roughly equivalent to the VerifyError the JVM-internal verifiers throw.
  22.  */
  23. public abstract class VerifierConstraintViolatedException extends RuntimeException {
  24.     // /** The name of the offending class that did not pass the verifier. */
  25.     // String name_of_offending_class;

  26.     private static final long serialVersionUID = 2946136970490179465L;
  27.     /** The specified error message. */
  28.     private String detailMessage;

  29.     /**
  30.      * Constructs a new VerifierConstraintViolatedException with null as its error message string.
  31.      */
  32.     VerifierConstraintViolatedException() {
  33.     }

  34.     /**
  35.      * Constructs a new VerifierConstraintViolatedException with the specified error message.
  36.      */
  37.     VerifierConstraintViolatedException(final String message) {
  38.         super(message); // Not that important
  39.         detailMessage = message;
  40.     }

  41.     /**
  42.      * Constructs a new VerifierConstraintViolationException with the specified error message and cause
  43.      */
  44.     VerifierConstraintViolatedException(final String message, final Throwable initCause) {
  45.         super(message, initCause);
  46.         detailMessage = message;
  47.     }

  48.     /**
  49.      * Extends the error message with a string before ("pre") and after ("post") the 'old' error message. All of these three
  50.      * strings are allowed to be null, and null is always replaced by the empty string (""). In particular, after invoking
  51.      * this method, the error message of this object can no longer be null.
  52.      */
  53.     public void extendMessage(String pre, String post) {
  54.         if (pre == null) {
  55.             pre = "";
  56.         }
  57.         if (detailMessage == null) {
  58.             detailMessage = "";
  59.         }
  60.         if (post == null) {
  61.             post = "";
  62.         }
  63.         detailMessage = pre + detailMessage + post;
  64.     }

  65.     /**
  66.      * Returns the error message string of this VerifierConstraintViolatedException object.
  67.      *
  68.      * @return the error message string of this VerifierConstraintViolatedException.
  69.      */
  70.     @Override
  71.     public String getMessage() {
  72.         return detailMessage;
  73.     }
  74. }