[code-reflection] Integrated: Enhance JavaType::type to deal with inner classes

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Jun 18 12:32:43 UTC 2025


On Tue, 17 Jun 2025 14:54:05 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> In some cases, the `JavaType::type(Type)` factory loses information about enclosing/enclosed type.
> This is due to the fact that, when the type in question contains some generic parameterization, the enclosing/enclosed relationship is reified in the `ParameterizedType` class.
> However, if the type is non-generic, it is modelled as a simple `Class` -- and the enclosing/enclosed relationship is lost.
> 
> This PR enhances the factory to recover the enclosing type using the reflective information available:
> * the class is a non-static member class. The enclosing type is the class in which the class is declared
> * the class is a local class, defined in a method `m`. If `m` is non-static, the enclosing type is the class declaring `m`
> * the class is a local class, defined in a constructor of class `C`. The enclosing type is `C`
> * otherwise, there's no enclosing type.
> 
> Note that there are some [known pathological cases](https://bugs.openjdk.org/browse/JDK-8162500) where the enclosing class information cannot be reconstructed from the information we have available in the bytecode, but this should not be a big issue for the time being.

This pull request has now been integrated.

Changeset: aefb9f66
Author:    Maurizio Cimadamore <mcimadamore at openjdk.org>
URL:       https://git.openjdk.org/babylon/commit/aefb9f665652caa3387216dab76d2b82dd547451
Stats:     73 lines in 2 files changed: 73 ins; 0 del; 0 mod

Enhance JavaType::type to deal with inner classes

Reviewed-by: psandoz

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

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


More information about the babylon-dev mailing list