8019292: Better Attribute Value Exceptions
authorsjiang
Tue, 06 Aug 2013 10:33:42 +0200
changeset 20836 c42fc815438d
parent 20835 56b90be9f6e2
child 20837 a9837567647e
8019292: Better Attribute Value Exceptions Reviewed-by: dfuchs, dholmes, ahgross
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 <CODE>BadAttributeValueExpException</CODE> 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();
+        }
+    }
  }