RFR: 8307512: Provide more information in message of NoSuchFieldException thrown by Class

Daohan Qu dqu at openjdk.org
Fri Jun 23 07:52:16 UTC 2023


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.)

-------------

Commit messages:
 - Add more info in the exception message

Changes: https://git.openjdk.org/jdk/pull/14624/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14624&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8307512
  Stats: 6 lines in 1 file changed: 4 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/14624.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14624/head:pull/14624

PR: https://git.openjdk.org/jdk/pull/14624


More information about the core-libs-dev mailing list