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

use Unsafe.put*Volatile methods to set final fields during default deserialization

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P3
    • Resolution: Future Project
    • 5.0
    • 8
    • core-libs

    Backports

      Description

        Currently, when ObjectInputStream.defaultReadObject sets the values of an object's serializable fields, it always uses the methods Unsafe.put{Object,Boolean,Int,...}, regardless of whether or not the field is final-- for final fields, it should instead use the methods Unsafe.put{Object,Boolean,Int,...}Volatile, in order to ensure the desired memory model semantics for final fields upon (default) deserializaion be similar to normal construction.

        With this change, setting of final fields by default deserialization would be implemented like setting of final fields via reflection (using Field.set after setAccessible(true)). The JLS covers this topic somewhat generally here:

        http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.5.3

        The issue is also mentioned here, in a bullet of the "Miscellany" section near the end:

        http://gee.cs.oswego.edu/dl/jmm/cookbook.html

        Attachments

          Issue Links

            Activity

              People

                alanb Alan Bateman
                peterjones Peter Jones
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: