Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8240314

Change serial form of javax.management.BadAttributeValueExpException field 'val'

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 15
    • core-svc
    • None
    • binary, behavioral
    • minimal
    • Hide
      The stream format is type compatible; the value written is always a String. If a Object (non-String) value is read from the stream it is replaced with a descriptive string value.
      The primary use of BadAttributeValueExpException is in live RMI communications using the javax.management API.
      Persistent serialized values of `BadAttributeValueExpException` are non-existent or extremely rare.
      Show
      The stream format is type compatible; the value written is always a String. If a Object (non-String) value is read from the stream it is replaced with a descriptive string value. The primary use of BadAttributeValueExpException is in live RMI communications using the javax.management API. Persistent serialized values of `BadAttributeValueExpException` are non-existent or extremely rare.
    • 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 {...}        

            rriggs Roger Riggs
            rriggs Roger Riggs
            Brian Burkhalter, Lance Andersen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: