001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.bcel.verifier.exc; 018 019/** 020 * Instances of this class are thrown by BCEL's class file verifier "JustIce" whenever verification proves that some 021 * constraint of a class file (as stated in the Java Virtual Machine Specification, Edition 2) is violated. This is 022 * roughly equivalent to the VerifyError the JVM-internal verifiers throw. 023 */ 024public abstract class VerifierConstraintViolatedException extends RuntimeException { 025 // /** The name of the offending class that did not pass the verifier. */ 026 // String name_of_offending_class; 027 028 private static final long serialVersionUID = 2946136970490179465L; 029 /** The specified error message. */ 030 private String detailMessage; 031 032 /** 033 * Constructs a new VerifierConstraintViolatedException with null as its error message string. 034 */ 035 VerifierConstraintViolatedException() { 036 } 037 038 /** 039 * Constructs a new VerifierConstraintViolatedException with the specified error message. 040 */ 041 VerifierConstraintViolatedException(final String message) { 042 super(message); // Not that important 043 detailMessage = message; 044 } 045 046 /** 047 * Constructs a new VerifierConstraintViolationException with the specified error message and cause 048 */ 049 VerifierConstraintViolatedException(final String message, final Throwable initCause) { 050 super(message, initCause); 051 detailMessage = message; 052 } 053 054 /** 055 * Extends the error message with a string before ("pre") and after ("post") the 'old' error message. All of these three 056 * strings are allowed to be null, and null is always replaced by the empty string (""). In particular, after invoking 057 * this method, the error message of this object can no longer be null. 058 */ 059 public void extendMessage(String pre, String post) { 060 if (pre == null) { 061 pre = ""; 062 } 063 if (detailMessage == null) { 064 detailMessage = ""; 065 } 066 if (post == null) { 067 post = ""; 068 } 069 detailMessage = pre + detailMessage + post; 070 } 071 072 /** 073 * Returns the error message string of this VerifierConstraintViolatedException object. 074 * 075 * @return the error message string of this VerifierConstraintViolatedException. 076 */ 077 @Override 078 public String getMessage() { 079 return detailMessage; 080 } 081}