Integrated: 8314621: ClassNotFoundException due to lambda reference to elided anonymous inner class
Vicente Romero
vromero at openjdk.org
Thu Nov 16 16:52:45 UTC 2023
On Thu, 16 Nov 2023 04:29:51 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> If code like the one below is executed:
>
>
> class ClassNotFoundExceptionDueToPrunedCodeTest {
> public static void main(String... args) {
> var o = false ? new Object() {} : null;
> Runnable r = () -> {
> System.out.println(o == o);
> };
> r.run();
> }
> }
>
> the runtime throws ClassNotFoundException. What is happening here is that the compiler is doing some "optimizations" basically in this case not generating code for the "true part" of the conditional as it will never be executed. The issue here is that the type of `o` will be the type of the anonymous class pruned by this optimization. Later on `o` is captured by the lambda and thus the exception. The proposed solution here is not to prune dead code if it is defining an anonymous class to avoid similar situations.
> TIA
This pull request has now been integrated.
Changeset: d6aa7c8b
Author: Vicente Romero <vromero at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/d6aa7c8ba0e727356562561d939c4965b69d7817
Stats: 216 lines in 5 files changed: 68 ins; 142 del; 6 mod
8314621: ClassNotFoundException due to lambda reference to elided anonymous inner class
Reviewed-by: jlahoda
-------------
PR: https://git.openjdk.org/jdk/pull/16683
More information about the compiler-dev
mailing list