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

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

XMLWordPrintable

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

        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

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: