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

Claes Redestad claes.redestad at oracle.com
Fri Jan 22 15:56:54 UTC 2016

Hi Roger,

right, I accidentally eliminated the accessor by (re-/)moving the 
constant which altered the serialization shape, which was the issue
here. Widening the field to package-private would have caused the same 



On 2016-01-22 16:50, Roger Riggs wrote:
> Hi Claes,
> I'm not sure it helps much, but making the ZERO_LENGTH_ENUM_ARRAY 
> package-private
> (instead of private) will eliminate the need for the accessor.  It is 
> not mutable so there's no extra risk.
> Roger
> On 1/22/2016 10:44 AM, Claes Redestad wrote:
>> On 2016-01-22 15:22, Chris Hegarty wrote:
>>> 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?
>>> 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.
>> I backed out the serial version UID change and reran the test, same 
>> thing.
>> I dug deeper, as this is a bit vexxing...
>> While a static field does not in and of itself cause the generated 
>> UID to change,
>> the private ZERO_LENGTH_ENUM_ARRAY is being accessed from 
>> SerializationProxy
>> class, thus javac generates a package-private synthetic method 
>> (access$000) which
>> will be accounted for when generating serialVersionUID. That's 
>> unfortunate.
>> I ran a few experiments to confirm this:
>> - Adding a package-private static method to EnumSet makes the test fail
>> - Adding any static field and the test keep passing
>> So it seems our options here are limited.
>> Thanks!
>> /Claes

More information about the core-libs-dev mailing list