Some core reflection APIs look for methods in classfile format that are 
expected to be present from the Java compiler. These APIs are: 
`Class.getEnclosingMethod`/`Constructor` and `RecordComponent.getAccessor`.

Currently, the Class ones throw `InternalError`, and the RecordComponent one 
returns null. These are not suitable behaviors as `InternalError` indicates an 
unrecoverable VM error, and a null return can propagate the error downstream 
and is not informative.

I propose to make these methods all throw `NoSuchMethodError`, a subtype of 
`LinkageError` and `IncompatibleClassChangeError`, which more accurately 
reflects the cause of these scenarios. This is also more in line with other 
failure modes of APIs like `Class.getDeclaringClass`, which throws 
`NoClassDefFoundError`.

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

Commit messages:
 - Missing methods should throw NSME

Changes: https://git.openjdk.org/jdk/pull/30506/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=30506&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8381377
  Stats: 59 lines in 4 files changed: 44 ins; 7 del; 8 mod
  Patch: https://git.openjdk.org/jdk/pull/30506.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/30506/head:pull/30506

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

Reply via email to