# HG changeset patch # User sjiang # Date 1375778022 -7200 # Node ID c42fc815438d4e9e8215e5d3e6df3d0f4b550883 # Parent 56b90be9f6e2f3d4fc74cf39317cac490ea9dba7 8019292: Better Attribute Value Exceptions Reviewed-by: dfuchs, dholmes, ahgross diff -r 56b90be9f6e2 -r c42fc815438d jdk/src/share/classes/javax/management/BadAttributeValueExpException.java --- a/jdk/src/share/classes/javax/management/BadAttributeValueExpException.java Sun Aug 04 02:50:02 2013 +0400 +++ b/jdk/src/share/classes/javax/management/BadAttributeValueExpException.java Tue Aug 06 10:33:42 2013 +0200 @@ -25,6 +25,9 @@ package javax.management; +import java.io.IOException; +import java.io.ObjectInputStream; + /** * Thrown when an invalid MBean attribute is passed to a query @@ -41,17 +44,19 @@ private static final long serialVersionUID = -3105272988410493376L; /** - * @serial The attribute value that originated this exception + * @serial A string representation of the attribute that originated this exception. + * for example, the string value can be the return of {@code attribute.toString()} */ private Object val; /** - * Constructs an BadAttributeValueExpException with the specified Object. + * Constructs a BadAttributeValueExpException using the specified Object to + * create the toString() value. * * @param val the inappropriate value. */ public BadAttributeValueExpException (Object val) { - this.val = val; + this.val = val == null ? null : val.toString(); } @@ -62,4 +67,25 @@ return "BadAttributeValueException: " + val; } + private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { + ObjectInputStream.GetField gf = ois.readFields(); + Object valObj = gf.get("val", null); + + if (valObj == null) { + val = null; + } else if (valObj instanceof String) { + val= valObj; + } else if (System.getSecurityManager() == null + || valObj instanceof Long + || valObj instanceof Integer + || valObj instanceof Float + || valObj instanceof Double + || valObj instanceof Byte + || valObj instanceof Short + || valObj instanceof Boolean) { + val = valObj.toString(); + } else { // the serialized object is from a version without JDK-8019292 fix + val = System.identityHashCode(valObj) + "@" + valObj.getClass().getName(); + } + } }