<div dir="ltr">On a side note, does VM spec require all strict fields to be already assigned via putfield (i.e. no missing assignment, even ones with default zero values) before a super constructor call? (This doesn't affect the correctness of strict fields, as unassigned fields will just have default zero values published)<div>If it doesn't, having no restriction on strict assignment for this-delegating constructors would be a great step toward simplification; but if it does, I think the super-calling constructor has diverged from this-calling constructor enough that adding another no-assignment-in-this-caller rule doesn't hurt that much.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 6, 2024 at 10:01 AM John Rose <<a href="mailto:john.r.rose@oracle.com">john.r.rose@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 29 Jan 2024, at 10:22, Dan Smith wrote:<br>
<br>
>><br>
>> As I understand the current design intent, a constructor that calls<br>
>> 'this' is forbidden from assigning to a strict field, because that<br>
>> will lead to a duplicate assignment in a constructor that calls<br>
>> 'super'.<br>
>><br>
>> This language appears to say the opposite. It seems to state that only<br>
>> the first constructor of the current class can assign the class's<br>
>> strict instance fields. If that is the case, then further constructors<br>
>> (including the one that calls 'super') are forbidden from assigning to<br>
>> strict instance fields.<br>
><br>
> Hello,<br>
> the problem is not duplicate assignment, as you said that part of the spec allows that,<br>
> the problem is assignment of final fields after a call to super() or this() because when the assignment occurs, 'this' may have already leaked to another context.<br>
><br>
> Right.<br>
><br>
> There is a *language* rule that final fields must not be assigned more than once. (Specifically, they must be definitely unassigned before their assignment; we'll add a rule that final fields must be definitely assigned before a 'this()' call.)<br>
><br>
> In the *JVM*, the only new thing we're guarding against is assignments after the constructor call. All assignments before a constructor call, duplicate or not, are allowed.<br>
<br>
This might be worth a non-normative note, to the effect of, “One may notice that the VM may assign strict fields before this-calls in the VM. Java compilers do not issue putfield instructions at such points, and we do not expect them to do so in the future. A special restriction on such assignments would add no value.”<br>
</blockquote></div>