RFR: 8307512: Provide more information in message of NoSuchFieldException thrown by Class
Chen Liang
liach at openjdk.org
Fri Jun 23 09:33:04 UTC 2023
On Fri, 23 Jun 2023 07:44:31 GMT, Daohan Qu <dqu at openjdk.org> wrote:
> Similar to #11745 , this patch adds more information for `NoSuchFieldException` thrown by `getField()` or `getDeclaredField()` of `java.lang.Class`. The error message changes like the example below:
> 1. For `getField()`
>
> Before this change:
>
> Exception in thread "main" java.lang.NoSuchFieldException: i
> …
>
> After this change:
>
> Exception in thread "main" java.lang.NoSuchFieldException: Class 'Test' does not have member field 'i'
> …
>
>
> 2. For `getDeclaredField()`
>
> Before this change:
>
> Exception in thread "main" java.lang.NoSuchFieldException: i
> …
>
> After this change:
>
> Exception in thread "main" java.lang.NoSuchFieldException: Class 'Test' does not have declared field 'i'
> …
>
>
> Tests `tier1-3` has passed for release build on Linux x86-64. (With one failure not related to this.)
I think a message like 'Class.field' is better, more consistent with methodToString's behavior.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14624#issuecomment-1604005192
More information about the core-libs-dev
mailing list