Class.getRecordComponent() javadoc doesn't specify its behavior if the accessor of a record component is not present

Remi Forax forax at univ-mlv.fr
Thu Oct 10 21:42:37 UTC 2019


You also have a lot of methods that throw a NoSuchMethodException when a method is not found.

The feature is Record, no record component, so i believe that ignoring the wrongly formatted record component is not what we want.
I don't recall that there is a method in the reflection API that returns null for an array of members so i think the best is to throw exceptions if there is not corresponding accessor and as Maurizio said, ignore unknown annotations.

Rémi

----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>, "Harold David Seigel" <harold.seigel at oracle.com>, "amber-dev"
> <amber-dev at openjdk.java.net>
> Envoyé: Jeudi 10 Octobre 2019 22:46:33
> Objet: Re: Class.getRecordComponent() javadoc doesn't specify its behavior if the accessor of a record component is not
> present

> Most reflective methods err on the side of returning null rather than
> failing.  We could argue about whether that's the right choice, but
> that's the precedent that was set early on (just as many methods return
> arrays, when we'd rather they return lists.)
> 
> On 10/10/2019 4:03 PM, Maurizio Cimadamore wrote:
>> It's the usual question: do we fail when we access things reflectively
>> that don't seem to be there (either fully or partially) ? Or do we
>> silently ignore?
>>
>> I know that we have examples of both; for instance, nestmates went the
>> 'throw an exception' path if a member of the nest cannot be found; but
>> annotations went a different path, and annotations that are not found
>> are simply discarded.
>>
>> One might argue that annotations are 'metadata' so less crucial than
>> properties such as record component-ness or nestmate-ness. But still
>> there's a choice.
>>
>> And, whatever we do, we should probably be consistent with any kind of
>> error that could popup when parsing the record component attribute,
>> such as illegal modifiers and such. But, I guess for missing
>> annotations on a record component we should be consistent with the
>> rest of the JDK, and just drop them on the floor.
>>
>> Maurizio
>>
>> On 10/10/2019 20:55, Harold Seigel wrote:
>>> The VM should throw a NoSuchMethodError exception in that case?
>>>
>>> Thanks, Harold
>>>
>>> On 10/10/2019 3:42 PM, Vicente Romero wrote:
>>>> that shouldn't happen, the compiler would generate the accessor if
>>>> not present, I guess the VM should verify for that too
>>>>
>>>> Vicente
>>>>
>>>> On 10/10/19 2:36 PM, Remi Forax wrote:
>>>>> As the title says,
>>>>> Class.getRecordComponent() javadoc doesn't specify its behavior if
>>>>> the accessor of a record component is not present.
>>>>>
>>>>> regards,
>>>>> Rémi


More information about the amber-dev mailing list