RFR 8231314: java.time serialization warning cleanup

Peter Levart peter.levart at gmail.com
Mon Sep 23 08:44:12 UTC 2019

Once more, for the list (sorry)...


On 9/21/19 12:31 PM, Chris Hegarty wrote:
> Roger,
>> On 20 Sep 2019, at 19:51, Roger Riggs <Roger.Riggs at oracle.com> wrote:
>> Please review code cleanup that will remove the need to suppress soon 
>> to be introduced
>> warnings [1] about static typing of serialization related fields.
>> A few of the implementation Ser classes that serialize java.time 
>> types are affected.
>> Webrev:
>> http://cr.openjdk.java.net/~rriggs/webrev-warn-serializable-8231314/
> I think the change is fine, just a few comments..
> - AbstractChronology is not necessarily is not always Serializable, 
> but writeReplace expects that it is.
> Since this is a package-private method, then I assume that it will 
> only ever be called by Serializable subtypes or the serialization 
> framework itself.
> - time/chrono/Ser.java : it’s kinda awkward to have to cast the return 
> of readExternal, especially since the set of types is locked down, but 
> without these readExternal methods returning xxxImpl types there is 
> little choice.

readExternal package-private methods could return Serializable, but then 
those methods would have to cast. Perhaps this would be better as it is 
"closer" to the real impl.

Another option (as I mentioned in previous message) would be to simply 
mark the Ser field as transient. The fact that currently it always holds 
an instance that *is* Serializable is just a coincidence, because it 
acts as a serialization proxy for Serializable implementations. Nothing 
in the logic of Ser class "requires" the instance assigned  to the field 
to be in fact Serializable.

Regards, Peter

More information about the core-libs-dev mailing list