[code-reflection] Integrated: Fix issues with local class creation from reflectable constructs
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Dec 3 22:16:27 UTC 2025
On Wed, 3 Dec 2025 17:42:11 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> Instantiation of local class from reflectable methods/lambdas is generally supported (although we do not support code reflection on local class members themselves).
>
> However, when testing I found there are many gaps in the current story:
>
> * existing support works or not depending on _where_ the local class is defined
> * when the local class to create contains its own captures, and the local class is inside a lambda expression, we just fail with `UnsupportedOperationException` (!!)
> * when a lambda tries to allocate a local class that was declared outside the lambda, the lambda code has no idea of which captures should come with the local class
> * when a lambda tries to allocate a regular member inner class with an implicit enclosing `this`, the lambda itself is not marked as capturing `this`, so model generation fails
>
> I addressed (I hope :-) ) all the above issues, and added several tests to check correctness.
>
> The main fix is to share the code to compute the local captures associated with a local class. We should compute such captures whenever we see a class declaration, both in `ReflectMethods` and in all its companion visitors -- otherwise the risk is that we will run some code that will require knowledge of the local class capture, but such knowledge is not available yet.
This pull request has now been integrated.
Changeset: eff881e1
Author: Maurizio Cimadamore <mcimadamore at openjdk.org>
URL: https://git.openjdk.org/babylon/commit/eff881e1f9c145823340f01e30d1262db94122e4
Stats: 169 lines in 2 files changed: 147 ins; 17 del; 5 mod
Fix issues with local class creation from reflectable constructs
Reviewed-by: psandoz
-------------
PR: https://git.openjdk.org/babylon/pull/723
More information about the babylon-dev
mailing list