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

I think the proposal is okay, I can't imagine anything relying on InternalError 
(or null for the record component accerssor). I've added myself as Reviewer to 
the CSR.

src/java.base/share/classes/java/lang/Class.java line 1473:

> 1471:             }
> 1472: 
> 1473:             throw new NoSuchMethodError(enclosingCandidate.getName() + 
> "." + enclosingInfo.getName() + enclosingInfo.getDescriptor());

I think NoSuchMethodError makes sense here. Maybe split the line to avoid the 
really long line.

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

Marked as reviewed by alanb (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/30506#pullrequestreview-4036674270
PR Review Comment: https://git.openjdk.org/jdk/pull/30506#discussion_r3015271813

Reply via email to