Trust final fields in records

Mandy Chung mandy.chung at
Fri Jun 12 17:08:02 UTC 2020

I got that one.  My reply was specific to what Johannes mentioned about 
breaking Jackson which I think it's not an issue.

W.r.t. third-party serialization frameworks, is it better to turn this 
on now in 15 and motivate maintainers of these frameworks to make change 
and support records?

Once we get more feedback from 15, we can decide whether making final 
fields of records not-modifiable in the first or second release when 
records exit preview???


On 6/12/20 9:56 AM, Brian Goetz wrote:
> My concern about serialization frameworks is not so much that the 
> setAccessible will fail (it won’t), but that they are not ready to 
> treat records specially, so they will try to deserialize them like any 
> other class, and then it will fail.
> If we make this change when records exit preview, this will catch 
> maintainers of these frameworks unaware — things will just start 
> breaking when their clients use records.  But if we give them a grace 
> period (e.g., lock it down in 17), we need to ensure that they’ll use 
> that time effectively, and not just kick the can down the road.
>> On Jun 12, 2020, at 12:53 PM, Mandy Chung <mandy.chung at 
>> <mailto:mandy.chung at>> wrote:
>> No change on setAccessible that will succeed on any fields as it is 
>> today.
>> The proposed change is that final fields of a record are not 
>> modifiable (i.e. no reflective write access) and Field::set on a 
>> Field object with no reflective write access will throw 
>> IllegalAccessException.
>> Today Field::set behavior:
>> - Static final fields have no write access
>> - Non-static final fields in a hidden class have no write access
>> - Non-static final fields on normal classes (that are not records) 
>> have reflective write access
>> No change to the above.
>> Mandy
>> [1] 
>> On 6/12/20 4:35 AM, Johannes Kuhn wrote:
>>> Jackson will break. It loves to call setAccessible on everything - 
>>> even when explicitly disabled [1].
>>> The other thing to consider is if setAccessible should fail, or if 
>>> it should still allow read access, similar to static final fields.
>>> - Johannes
>>> [1]:
>>> On 12-Jun-20 12:57, Brian Goetz wrote:
>>>> If the fields cannot be made accessible, this means that 3rd party 
>>>> serialization frameworks will choke on records, right?
>>>> Sent from my iPad
>>>>> On Jun 12, 2020, at 5:10 AM, Chris Hegarty 
>>>>> <chris.hegarty at> wrote:
>>>>>> On 12 Jun 2020, at 02:52, Mandy Chung <mandy.chung at> 
>>>>>> wrote:
>>>>>> Hi Christoph,
>>>>>> I can sponsor your patch.  I create 
>>>>> This is great. I remember thinking (saying?) similar when we 
>>>>> settled on record serialization not needing to muck around with 
>>>>> field stuffing (among the motivating factors for how records 
>>>>> deserialize). This is a great step forward, nice to see it 
>>>>> progressing.
>>>>> -Chris.

More information about the valhalla-dev mailing list