RFR: 8335478: Add notes for Error handling in Method.invoke and Constructor.newInstance

Chen Liang liach at openjdk.org
Mon Jul 1 21:53:44 UTC 2024


`Method.invoke` and `Constructor.newInstance` wraps `Error` in `InvocationTargetException`, which is bug-prone for users. Worse, this is only ambiguously mentioned in the API specification.

This patch proposes to explicitly mention that `InvocationTargetException` wraps any throwable, and adds an API notes section describing the risk of not handling `InvocationTargetException` (and thereby ignoring the wrapped errors), to advise against future user errors.

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

Commit messages:
 - 8335478: Add notes for Error handling in Method.invoke and Constructor.newInstance

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

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


More information about the core-libs-dev mailing list