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

XMLWordPrintable

    • Type: Bug
    • Resolution: Future Project
    • Priority: P3
    • 8
    • Affects Version/s: 5.0
    • Component/s: 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

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: