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