RFR: 8343064: ClassFormatError: Illegal class name from InnerClassLambdaMetafactory
Chen Liang
liach at openjdk.org
Tue Nov 5 19:21:59 UTC 2024
On Tue, 5 Nov 2024 18:29:52 GMT, Chen Liang <liach at openjdk.org> wrote:
> After the ClassFile API migration, when serializable lambdas are requested for hidden class callers, illegal class name is generated for the serialization methods, which previously had legal yet unusable class names, as hidden classes cannot be described by a `CONSTANT_Class_info`.
>
> This patch restores a similar older behavior of using legal yet unusable class names. Previously, the invalid `.` in hidden class names was replaced by a `/` as if a package separator; this patch changes it to a `_` like that in the generated lambda's class name.
>
> The bug report shows some unintended and erroneous usages of `LambdaMetafactory`. To clarify and to persuade against misuse, I added a paragraph of API notes to `LambdaMetafactory`, describing the impact of this API being designed to support Java language features. In particular, I used the scenario where people assumed LMf generates weak hidden classes, which happened in this issue report and in #12493, that misuse can lead to resource leaks.
Test added to ensure that serializable lambdas can be created and its SAM can be called when the caller is a hidden class. Note that we do not guarantee anything about the serialization functionality itself. We can add serialization support for hidden classes in the future, but I doubt we do as it is niche and requires larger implementation changes.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21912#issuecomment-2457973143
More information about the core-libs-dev
mailing list