Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
8019292: Better Attribute Value Exceptions
Browse files Browse the repository at this point in the history
Reviewed-by: dfuchs, dholmes, ahgross
  • Loading branch information
sjiang committed Aug 6, 2013
1 parent 960a2cd commit af2361e
Showing 1 changed file with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,17 +44,19 @@ public class BadAttributeValueExpException extends Exception {
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();
}


Expand All @@ -62,4 +67,25 @@ public String toString() {
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();
}
}
}

0 comments on commit af2361e

Please sign in to comment.