-
CSR
-
Resolution: Approved
-
P3
-
None
-
binary, behavioral
-
minimal
-
-
Other
-
SE
Summary
The type of the serializable field javax.management.BadAttributeValueExpException.val
should be changed from Object
to String
.
Problem
Since JDK 1.8 (2013), the value of the val
field has been restricted to String. The constructor invokes the toString
method of the argument to produce the string. During deserialization, any non-String value is replaced by a string representing the attribute.
The restriction has been back ported to JDK 1.7.
However, the type of the field was not changed from Object to String due to compatibility concerns about existing serialized streams. Those concerns are moot since the implementation of readObject
consistently replaces any non-String value with a string representation.
Persistent serialized values of BadAttributeValueExpException
are rare as the primary use is in live RMI use cases.
Solution
Changing the type of the val
field will match the type of the value and has no compatibility impact since the value of the field is ensured to be a String (or null) by the readObject
method and the constructor.
Incidentally, the implementation to replace any non-String value with a string produces a different implementation specific string that is not specialized for numeric types. This allows the removal of unused code and a unnecessary dependency on the security manager.
Specification
BadAttributeValueExpException.java:
@@ -48,7 +48,7 @@
* for example, the string value can be the return of {@code attribute.toString()}
*/
@SuppressWarnings("serial") // See handling in constructor and readObject
- private Object val;
+ private String val;
@@ -68,6 +68,16 @@ public class BadAttributeValueExpExcepti
return "BadAttributeValueException: " + val;
}
+ /**
+ * Restores the fields of a BadAttributeValueExpException from the stream.
+ * If the 'val' field in the stream does not contain a string
+ * it is replaced with an implementation specific string representation
+ * of the value in the stream.
+ *
+ * @param ois an ObjectInput Stream
+ * @throws IOException thrown if an error occurs
+ * @throws ClassNotFoundException if a class can not be found
+ */
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {...}
- csr of
-
JDK-8232622 Technical debt in BadAttributeValueExpException
-
- Resolved
-
- relates to
-
JDK-8240957 Clarify BadAttributeValueExpException readObject method
-
- Resolved
-