On Mon, 15 Jun 2026 15:39:49 GMT, ExE Boss <[email protected]> wrote:

>> This is a good question. We went around this a few times during JEP 500 and 
>> decided to send the conditional cases through 
>> checkAllowedToUnreflectFinalSetter, the benefit being that everything 
>> related to the CLI options to allow mutation of finals is in one place. You 
>> are right that the strict final fields case can't be changed by the CLI 
>> options so isStrictInit can be checked eariler. It means that 
>> newFieldAccessor must be created without a setter, which is a good thing.
>
> I take it that “best done here” refers to having `Field​::isTrustedFinal()` 
> return `true` for strictly initialised fields, the correct fix for which 
> would be to update `fieldDescriptor​::is_trusted_final()` to include 
> `is_strict()` in the `||` portion of:
> https://github.com/openjdk/valhalla/blob/9cd13e6903a025ee82be54217ab76256b392a9ce/src/hotspot/share/runtime/fieldDescriptor.cpp#L46-L50
> 
> e.g.:
> ```c++
> bool fieldDescriptor::is_trusted_final() const {
>   InstanceKlass* ik = field_holder();
>   return is_final() && (is_static() || is_strict()
>                         || ik->is_hidden() || ik->is_record() || 
> ik->is_inline_klass()
>                         || (ik->is_abstract() && !ik->is_identity_class() && 
> !ik->is_interface()));
> }

I don't think we should expand this "trusted final" concept.

-------------

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2548#discussion_r3415162550

Reply via email to