[code-reflection] RFR: Method code model uniquness [v2]
Paul Sandoz
psandoz at openjdk.org
Tue Apr 29 16:34:00 UTC 2025
On Tue, 29 Apr 2025 14:09:55 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/reflect/Method.java line 233:
>>
>>> 231: /* package */
>>> 232: Optional<?> setCodeModelIfNeeded(Function<Method, Optional<?>> modelFactory) {
>>> 233: Optional<?> localRef = root.codeModel;
>>
>> I was looking at `Method` and found this method that does more or less a similar operation:
>>
>>
>> // Accessor for generic info repository
>> @Override
>> MethodRepository getGenericInfo() {
>> var genericInfo = this.genericInfo;
>> if (genericInfo == null) {
>> var root = this.root;
>> if (root != null) {
>> genericInfo = root.getGenericInfo();
>> } else {
>> genericInfo = MethodRepository.make(getGenericSignature(), getFactory());
>> }
>> this.genericInfo = genericInfo;
>> }
>> return genericInfo;
>> }
>>
>>
>> Should we copy/reuse same logic?
>
> E.g. note that `root` can be null!
Yes, pattern is i think better. It recursively enters the root instance, whose root has to be `null`, hence the check to determine whether to recurse or do the work.
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/415#discussion_r2066885346
More information about the babylon-dev
mailing list