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

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Jul 7 15:06:13 UTC 2025


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.

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

Commit messages:
 - Initial push

Changes: https://git.openjdk.org/babylon/pull/486/files
  Webrev: https://webrevs.openjdk.org/?repo=babylon&pr=486&range=00
  Stats: 164 lines in 7 files changed: 74 ins; 30 del; 60 mod
  Patch: https://git.openjdk.org/babylon/pull/486.diff
  Fetch: git fetch https://git.openjdk.org/babylon.git pull/486/head:pull/486

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


More information about the babylon-dev mailing list