On Mon, 30 Mar 2026 22:51:43 GMT, Chen Liang <[email protected]> wrote:
> 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`. > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). This pull request has been closed without being integrated. ------------- PR: https://git.openjdk.org/jdk/pull/30506
