RFR (XS): 8148044: Remove Enum[0] constants from EnumSet and EnumMap

Chris Hegarty chris.hegarty at oracle.com
Fri Jan 22 14:22:05 UTC 2016


Claes,

On 22/01/16 12:07, Claes Redestad wrote:
> On 2016-01-22 12:56, Claes Redestad wrote:
>> On 2016-01-22 12:53, Alan Bateman wrote:

>>> On 22/01/2016 11:34, Claes Redestad wrote:
>>>> :
>>>> During testing I discovered that EnumSet was missing a
>>>> serialVersionUID, which needs to be added.
>>> I assume this is not needed, it already has:
>>>
>>> @SuppressWarnings("serial") // No serialVersionUID due to usage of
>>> serial proxy pattern
>>
>> That's odd.. there's a jtreg test that fails if I don't explicitly add
>> the serialVersionUID (that's where I got the actual UID from). I'll
>> investigate.
>
> Right...  java/util/EnumSet/BogusEnumSet.java fails, which is an
> explicit test to verify a corrupt EnumSet doesn't deserialize properly:

Hmmm... this would indicate that the changes you have made has
affected the serial version UID automatically generated. I'm not
sure why removing a 'private static' field would do this. Is it
possible that you ran into this during development, but it is
not actually necessary with the final changes?

> java.io.InvalidClassException: java.util.EnumSet; local class
> incompatible: stream classdesc serialVersionUID = 1009687484059888093,
> local class serialVersionUID = 4168005130090799668
>      at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:618)
>      at
> java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1626)
>      at
> java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1521)
>      at
> java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1626)
>      at
> java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1521)
>      at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1777)
>      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1354)
>      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
>      at BogusEnumSet.deserialize(BogusEnumSet.java:91)
>      at BogusEnumSet.main(BogusEnumSet.java:78)
>      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>      at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>
>      at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>
>      at java.lang.reflect.Method.invoke(Method.java:520)
>      at
> com.sun.javatest.regtest.agent.MainActionHelper$SameVMRunnable.run(MainActionHelper.java:218)
>
>      at java.lang.Thread.run(Thread.java:804)

This test is a little fragile, but should be ok.

> It would seem the assessment that serialVersionUID is not needed when
> using the serial proxy pattern might be misguided (or is this a bug in
> ObjectInputStream)?

It is debate-able whether this is a test bug or not. But I think
we should not change the serialVersionUID for this class, whether
truly Serializable or not. Even though in practice it is not all
that useful.

Can you please revert the serialization parts of the change, and
rerun the test? To see if still passes or fails.

-Chris.



More information about the core-libs-dev mailing list