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

Fix wording in Javadoc of java.io.Serializable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 16
    • 7u51, 9
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.7.0_25"
      Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The Javadoc contains the following sentence: "To allow subtypes of non-serializable classes to be serialized, the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields. The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state. It is an error to declare a class Serializable if this is not the case. The error will be detected at runtime."

      The second sentence of this implies that the no-args constructor rule only applies if the subtype is "assum[ing] responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields".

      The fact is that the requirement is unconditional. Any class declared serializable must satisfy this requirement, whether or not it is assuming the responsibillity described. The Object Serialization Specification #1.10 simply says this: "A Serializable class must do the following: ... Have access to the no-arg constructor of its first nonserializable superclass
      ".

      The wording in the Javadoc needs to be amended, probably by removing the second sentence and quoting from the Specification instead.


      REPRODUCIBILITY :
      This bug can be reproduced always.

            smarks Stuart Marks
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: