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 /** The specified error message. */ 032 private String detailMessage; 033 034 /** 035 * Constructs a new VerifierConstraintViolatedException with null as its error message string. 036 */ 037 VerifierConstraintViolatedException() { 038 } 039 040 /** 041 * Constructs a new VerifierConstraintViolatedException with the specified error message. 042 */ 043 VerifierConstraintViolatedException(final String message) { 044 super(message); // Not that important 045 detailMessage = message; 046 } 047 048 /** 049 * Constructs a new VerifierConstraintViolationException with the specified error message and cause 050 */ 051 VerifierConstraintViolatedException(final String message, final Throwable initCause) { 052 super(message, initCause); 053 detailMessage = message; 054 } 055 056 /** 057 * Extends the error message with a string before ("pre") and after ("post") the 'old' error message. All of these three 058 * strings are allowed to be null, and null is always replaced by the empty string (""). In particular, after invoking 059 * this method, the error message of this object can no longer be null. 060 */ 061 public void extendMessage(String pre, String post) { 062 if (pre == null) { 063 pre = ""; 064 } 065 if (detailMessage == null) { 066 detailMessage = ""; 067 } 068 if (post == null) { 069 post = ""; 070 } 071 detailMessage = pre + detailMessage + post; 072 } 073 074 /** 075 * Returns the error message string of this VerifierConstraintViolatedException object. 076 * 077 * @return the error message string of this VerifierConstraintViolatedException. 078 */ 079 @Override 080 public String getMessage() { 081 return detailMessage; 082 } 083}