Path: blob/master/src/java.management/share/classes/javax/management/BadAttributeValueExpException.java
41155 views
/*1* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.management;2627import java.io.IOException;28import java.io.ObjectInputStream;293031/**32* Thrown when an invalid MBean attribute is passed to a query33* constructing method. This exception is used internally by JMX34* during the evaluation of a query. User code does not usually35* see it.36*37* @since 1.538*/39public class BadAttributeValueExpException extends Exception {404142/* Serial version */43private static final long serialVersionUID = -3105272988410493376L;4445/**46* @serial A string representation of the attribute that originated this exception.47* For example, the string value can be the return of {@code attribute.toString()}.48*/49@SuppressWarnings("serial") // See handling in constructor and readObject50private String val;5152/**53* Constructs a BadAttributeValueExpException using the specified Object to54* create the toString() value.55*56* @param val the inappropriate value.57*/58public BadAttributeValueExpException (Object val) {59this.val = val == null ? null : val.toString();60}616263/**64* Returns the string representing the object.65*/66public String toString() {67return "BadAttributeValueException: " + val;68}6970/**71* Restores the fields of a BadAttributeValueExpException from the stream.72* If the 'val' field in the stream does not contain a string73* it is replaced with an implementation specific string representation74* of the value in the stream.75*76* @param ois an ObjectInput Stream77* @throws IOException thrown if an error occurs78* @throws ClassNotFoundException if a class can not be found79*/80private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {81ObjectInputStream.GetField gf = ois.readFields();82Object valObj = gf.get("val", null);8384if (valObj instanceof String || valObj == null) {85val = (String)valObj;86} else { // the serialized object is from a version without JDK-8019292 fix87val = System.identityHashCode(valObj) + "@" + valObj.getClass().getName();88}89}90}919293