RFR: JDK-8277451: java.lang.reflect.Field::set on static field with invalid argument type should throw IAE [v2]
Mandy Chung
mchung at openjdk.java.net
Mon Nov 22 20:01:52 UTC 2021
On Sun, 21 Nov 2021 21:05:19 GMT, Alan Bateman <alanb at openjdk.org> 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
More information about the core-libs-dev
mailing list