RFR: 8307512: Provide more information in message of NoSuchFieldException thrown by Class
Chen Liang
liach at openjdk.org
Fri Jun 23 12:59:05 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.)
IMO #11745 is a bit too verbose, compared to the code that prints the absent method in NoSuchMethodError:
https://github.com/openjdk/jdk/blob/d1d2b55ce0b950e07f6e3761983f73fd58079627/src/hotspot/share/interpreter/linkResolver.cpp#L863-L871
Printing the descriptor directly suffices. Field descriptors are described by [JVMS 4.3.2](https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.3.2).
-------------
PR Comment: https://git.openjdk.org/jdk/pull/14624#issuecomment-1604245500
More information about the core-libs-dev
mailing list