RFR: JDK-8216558: Lookup.unreflectSetter(Field) fails to throw IllegalAccessException for final fields

Mandy Chung mandy.chung at oracle.com
Fri Jan 11 19:07:14 UTC 2019


This issue requires a spec change and it's a behavioral change. 
Field::set on a static final field throws IAE.  Although there are few 
cases in the world that hack around it, I think the compatibility risk 
is low in this change.

I added a suggested fix in the JBS issue.

Mandy

On 1/11/19 10:07 AM, Mandy Chung wrote:
> Hi Adam,
>
> This is indeed a bug.    I suggest to do the check in the checkAccess 
> method closes to where it performs the instance final field check.  
> Please also add a test case.
>
> Mandy
>
> On 1/11/19 6:38 AM, Adam Farley8 wrote:
>> Hi All,
>>
>> First; thanks for responding so quickly. :)
>>
>> Second, it sounds like changing the contents of a final field is
>> acceptable under the spec, but *not* changing the contents of a static
>> final field.
>>
>> The test case uploaded to the bug uses a static final field for the 
>> test,
>> so I think we can agree that the ability to create a setter for a static
>> final field is still a bug.
>>
>> It sounds like the same fix could work if we check for "static" when we
>> check for "final", with a modified message.
>>
>> As Field.set (post-setAccessible) fails to set the value of a static 
>> final
>> field, I think we can agree that unreflectSetter should fail to create a
>> setter MethodHandle for this same field.
>>
>> Best Regards
>>
>> Adam Farley
>> IBM Runtimes
>>



More information about the core-libs-dev mailing list