On Sun, 21 Nov 2021 21:05:19 GMT, Alan Bateman <[email protected]> wrote:
>> src/java.base/share/classes/jdk/internal/reflect/MethodHandleFieldAccessorImpl.java
>> line 72:
>>
>>> 70: */
>>> 71: protected IllegalArgumentException
>>> newGetIllegalArgumentException(Object o) {
>>> 72: return new IllegalArgumentException(getMessage(true, o != null
>>> ? o.getClass().getName() : ""));
>>
>> Hello Mandy,
>> With this change the `getMessage` may get passed an empty string, so it
>> would end up printing something like `Can not get ... field <fieldname> on`.
>> Do you think the `getMessage` implementation should be tweaked not to print
>> the "on" if the `attemptedType` is empty?
>
>> Hello Mandy,
>> With this change the `getMessage` may get passed an empty string, so it
>> would end up printing something like `Can not get ... field <fieldname> on`.
>> Do you think the `getMessage` implementation should be tweaked not to print
>> the "on" if the `attemptedType` is empty?
>
> I suspect this was meant to be "null" rather than "".
With this patch, `newGetIllegalArgumentException` and
`newSetIllegalArgumentException` are now only called when obj is non-null and
the receiver type is of an invalid type. But it's better to improve this
exception message to handle null obj. I pushed the change to clean up this
code.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6490