[code-reflection] Integrated: Issue errors when quotable constructs are found inside inner classes

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Jul 8 10:41:06 UTC 2025


On Mon, 7 Jul 2025 15:01:34 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This PR adds check in `ReflectMethods` to issue errors when quotable methods, lambdas, method references are found inside an inner class. This includes member inner classes, local and anonymous inner classes, but static inner classes (sometimes referred to as *nested classes*) are ok.
> 
> The issue is that if we allowed code reflection in these places, we would need to come up with uniform treatment for compiler-generated captured symbols.
> Currently `ReflectMethods` just allows method in an inner class to refer to a variable or a method in the enclosing class freely. While this is correct from a source code perspective, by the time we translate to bytecode, such references are no longer possible, and are typically mediated by compiler-generated symbols such as `this$0`.
> 
> So, instead of generating a code model that might be unreliable, it is better, for now, to just disallow such cases.
> 
> In principle, we should just "skip over" code elements we cannot support, and generate bytecode as usual. Indeed this is where I started, but then I realized that the support for lambda conversion into `Quoted` does not make sense unless we enable code reflection (as there's no real functional interface target we can use there). For this reason, an error is generated instead.

This pull request has now been integrated.

Changeset: 815098b0
Author:    Maurizio Cimadamore <mcimadamore at openjdk.org>
URL:       https://git.openjdk.org/babylon/commit/815098b04e3960eb9ef5df1343968ce22401beed
Stats:     164 lines in 7 files changed: 74 ins; 30 del; 60 mod

Issue errors when quotable constructs are found inside inner classes

Reviewed-by: psandoz

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

PR: https://git.openjdk.org/babylon/pull/486


More information about the babylon-dev mailing list