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

Remi Forax forax at univ-mlv.fr
Fri Jan 11 12:56:35 UTC 2019


It's not wrong, it's part of the spec.
while most the semantics of the method handle is based on the bytecode semantics, the method unreflect* semantics are based on the java.lang.reflect semantics, so if field.set(object, value) is able to change the value of the field then unreflectSetter(field).invokeExact(object, value) has to change the value of the field too.

regards,
Rémi (with my JSR 292 Expert hat)

----- Mail original -----
> De: "Adam Farley8" <adam.farley at uk.ibm.com>
> À: "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Envoyé: Vendredi 11 Janvier 2019 13:46:01
> Objet: RFR: JDK-8216558: Lookup.unreflectSetter(Field) fails to throw IllegalAccessException for final fields

> Hi All,
> 
> I posit that you shouldn't be able to change the contents of a a final
> field.
> 
> However, if you use Field.setAccessible(true) before calling
> Lookup.unreflectSetter(Field), then you can get a MethodHandle that allows
> you to set the (reflected) value of a static final field.
> 
> This seems wrong to me, so here's a change to fix it.
> 
> webrev: http://cr.openjdk.java.net/~afarley/8216558/webrev/
> bug: https://bugs.openjdk.java.net/browse/JDK-8216558
> 
> Opinions invited.
> 
> Best Regards
> 
> Adam Farley
> IBM Runtimes
> 
> Unless stated otherwise above:
> IBM United Kingdom Limited - Registered in England and Wales with number
> 741598.
> Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU


More information about the core-libs-dev mailing list