[lworld] RFR: 8327695: [lworld] javac can generate incorrect code in inner class' constructors
Vicente Romero
vromero at openjdk.org
Sat Mar 16 22:32:05 UTC 2024
On Fri, 15 Mar 2024 17:20:06 GMT, Chen Liang <liach 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
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 2973:
>
>> 2971: outerThisSet = Set.of(thisArg);
>> 2972: } else {
>> 2973: outerThisSet.add(thisArg);
>
> Is this `java.util.Set`? If yes then `add` probably doesn't work on immutable sets.
got it, good catch, will fix thanks!
-------------
PR Review Comment: https://git.openjdk.org/valhalla/pull/1048#discussion_r1526622687
More information about the valhalla-dev
mailing list