On Wed, 17 Mar 2021 18:02:07 GMT, Claes Redestad <[email protected]> wrote:
>> src/java.base/share/classes/java/lang/invoke/MethodType.java line 418:
>>
>>> 416: public MethodType changeParameterType(int num, Class<?> nptype) {
>>> 417: if (parameterType(num) == nptype) return this;
>>> 418: checkPtype(nptype);
>>
>> `nptype` is never void but what about the check if `nptype` is not null?
>
> Other methods that delegate to `makeImpl` aren't doing up-front validation,
> so this change was made to get things more in line. It might be good to spell
> out that `makeImpl` does these checks for all its callers, though. (The
> `makeImpl` fast-path that execute before the validation can never return an
> invalid MethodType)
Generally we have a public API implementation to check the arguments upfront
for readability. In particular for this case, the validation cost is
negligible and removing the validation makes the code unclear where the
validation is done. I prefer to keep the validation there. It should check
that `nptype` is non-null and not `void.class`.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2300