# HG changeset patch
# User sjiang
# Date 1375797854 -7200
#      Tue Aug 06 16:04:14 2013 +0200
# Node ID d80e6f4a4eec26137af6726cfb8abfe108ce23ea
# Parent  de490a43861e05f3da489db136687b1dc6f1949a
8019292: Better Attribute Value Exceptions
Reviewed-by: dfuchs, dholmes, ahgross

diff -r de490a43861e -r d80e6f4a4eec src/share/classes/javax/management/BadAttributeValueExpException.java
--- openjdk/jdk/src/share/classes/javax/management/BadAttributeValueExpException.java	Fri Oct 25 22:43:09 2013 +0100
+++ openjdk/jdk/src/share/classes/javax/management/BadAttributeValueExpException.java	Tue Aug 06 16:04:14 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
@@ -51,7 +54,7 @@
      * @param val the inappropriate value.
      */
     public BadAttributeValueExpException (Object val) {
-        this.val = val;
+        this.val = val == null ? null : val.toString();
     }
 
 
@@ -62,4 +65,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();
+        }
+    }
  }
