[lworld] Integrated: 8327695: [lworld] javac can generate incorrect code in inner class' constructors

Vicente Romero vromero at openjdk.org
Mon Mar 18 14:22:58 UTC 2024


On Fri, 15 Mar 2024 15:40:04 GMT, Vicente Romero <vromero at openjdk.org> wrote:

> When dealing with value classes javac, as mandated by the spec, is placing field initializers before any invocation to `super()`. This works just fine most of the time but for cases like:
> 
> class JavacBug {
>     value class V1 {}
> 
>     value class V2 {
>         V1 v = new V1();
>     }
> 
>     void test() {
>         V2 v2 = new V2();
>     }
> 
>     public static void main(String... args) {
>         JavacBug jb = new JavacBug();
>         jb.test();
>     }
> }
> 
> javac is generating incorrect code for class V2 due to a getfield being generated to read the synthetic field storing the outer this before invoking the constructor for V1. The proposed change is changing the generated bytecode to read the outer this from the mandated parameter javac adds to inner class constructors,
> 
> TIA

This pull request has now been integrated.

Changeset: 5a130975
Author:    Vicente Romero <vromero at openjdk.org>
URL:       https://git.openjdk.org/valhalla/commit/5a13097581a05a9440b4c8e54d52c259057ff47e
Stats:     51 lines in 3 files changed: 51 ins; 0 del; 0 mod

8327695: [lworld] javac can generate incorrect code in inner class' constructors

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

PR: https://git.openjdk.org/valhalla/pull/1048



More information about the valhalla-dev mailing list