On 20 Mar 2015, at 13:03, David M. Lloyd <david.ll...@redhat.com> wrote:
...
> An interesting aspect of this approach is that it deals with a problem in the 
> serialization spec [1] where it specifically says that serializable classes 
> should be reading/writing stream fields always, and before reading/writing 
> other data:
> 
> In section 3.4: "Either ObjectInputStream's defaultReadObject or readFields 
> method must be called once (and only once) before reading any optional data 
> written by the corresponding writeObject method; even if no optional data is 
> read, defaultReadObject or readFields must still be invoked once."
> 
> In section 2.3: "Either ObjectOutputStream's defaultWriteObject or 
> writeFields method must be called once (and only once) before writing any 
> optional data that will be needed by the corresponding readObject method to 
> restore the state of the object; even if no optional data is written, 
> defaultWriteObject or writeFields must still be invoked once."
> 
> But classes (even JDK classes) often disregard this requirement, relying on 
> known implementation behavior and either reading/writing optional data before 
> fields or just not reading/writing fields at all.  So either the spec should 
> be updated (I've tried to do this but nobody seems to know how to modify this 
> old content I guess) to match behavior, or the spec should be enforced more 
> strictly - however doing the latter *will* break a lot of user code, *unless* 
> an alternative readObject method is introduced with the more strict 
> enforcement.  But I guess even in this case, the spec should be updated to 
> allow the implementation behaviour.

I do remember the thread on this [1]. I did try to locate the source of the 
Serialization spec, but never got to the bottom of it.

I think we should start a new thread on this, and see if we can agree proposed 
wording for the spec. I will then endeavour to have these amendments applied to 
the spec. ( In the meantime I’ll see if I can make progress on locating the 
spec source ).

-Chris.

[1] http://markmail.org/message/tpyws22lklyodb7p


> [1] 
> http://docs.oracle.com/javase/8/docs/platform/serialization/spec/serialTOC.html

Reply via email to