<div dir="ltr"><div>OK looks like you've tracked down the important stuff already.</div><div><br></div><div>The JEP advertises "flexibility" but in some ways the more important feature is safety, because it allows a subclass to prevent a superclass constructor from invoking an overridden method that would then see uninitialized subclass fields. This was a long-standing issue with Java constructors of course. Related is the "this-escape" warning which grew out of those same discussions, prior to the JEP itself, as a way to at least raise awareness of the problem.</div><div><br></div><div>Another nuance is that until this JEP the JLS's application of "static context" to constructors was out of touch with the reality of how the compiler has actually worked since JDK 8. See JDK-8301649 for a description of that. And there turned out to be more subtlety and corner cases in the "early construction" context than we initially realized, once you started looking at things like multiple nestings of local classes, etc. Note, many of these issues existed before this JEP; they just required more oddball syntax like this:</div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">public Foo(int x) {</span></div><div style="margin-left:40px"><span style="font-family:monospace"> super(switch (x) {</span></div><div style="margin-left:40px"><span style="font-family:monospace"> default -> {</span></div><div style="margin-left:40px"><span style="font-family:monospace"> class Bar {{ Foo.this.hashCode(); }} // should this be allowed?</span></div><div style="margin-left:40px"><span style="font-family:monospace"> yield x;</span></div><div style="margin-left:40px"><span style="font-family:monospace"> }</span></div><div style="margin-left:40px"><span style="font-family:monospace"> });</span></div><div style="margin-left:40px"><span style="font-family:monospace">}</span></div><div><br></div><div>And as you noted there was some "horse trading"; the original proposal had two additional "flexibilities" that were not included. The first was to use DA/DU analysis to verify exactly one super() or this() invocation. This would have allowed constructors like this:</div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">public Foo(int x) {<br></span></div><div style="margin-left:40px"><span style="font-family:monospace"> if (x < 0)</span></div><div style="margin-left:40px"><span style="font-family:monospace"> super(-x);</span></div><div style="margin-left:40px"><span style="font-family:monospace"> else</span></div><div style="margin-left:40px"><span style="font-family:monospace"> super(x);</span></div><div style="margin-left:40px"><span style="font-family:monospace">}</span></div><div><br></div><div>The second would have allowed super() or this() inside a try block:</div><div><br></div><div><div style="margin-left:40px"><span style="font-family:monospace">public Foo(Object obj) {<br></span></div><div style="margin-left:40px"><span style="font-family:monospace"> try {</span></div><div style="margin-left:40px"><span style="font-family:monospace"> super(obj.hashCode());</span></div><div style="margin-left:40px"><span style="font-family:monospace"> } catch (NullPointerException e) {</span></div><div style="margin-left:40px"><span style="font-family:monospace"> throw new </span><span style="font-family:monospace">IllegalArgumentException("illegal null value");</span></div><div style="margin-left:40px"><span style="font-family:monospace"> }</span></div><div style="margin-left:40px"><span style="font-family:monospace">}</span></div></div><div><br></div><div>This additional flexibility was deemed unnecessary - at least for now - which I think was the right call to facilitate getting it done (because of the reduced JLS impact).</div><div><br></div><div>-Archie</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 29, 2025 at 10:03 PM David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank">davidalayachew@gmail.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"><div dir="ltr"><div class="gmail_default" style="font-family:monospace">Thanks Archie!</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">To help limit your search, I went through all of Amber Dev and Amber Spec Experts, from Jan 2022 up to now. I only really found a whole bunch of "Sounds great to me" and "Where should we draw the line?". It may make sense to turn some of those "Where's the line?" questions, and turn them into FAQ answers, but nothing really popped out to me.</div><div class="gmail_default" style="font-family:monospace"><br>
</div><div class="gmail_default" style="font-family:monospace">That aside, I found a lot of discussion on Amber Dev, primarily Oct/Nov 2022. That seems to be where this whole thing started.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Btw, it was a very cool read to see a feature organically grow from a simple discussion to an actual JEP. It's a great guideline for how to do this right. Plus, more of it was out in the open than most JEP's, so easier to learn how to follow along.</div><br><div class="gmail_default" style="font-family:monospace">And finally, here is the work-in-progress thus far, in case you want to correct what I have done.</div><div><br></div><div><div style="font-family:monospace" class="gmail_default"><a href="https://github.com/openjdk/amber-docs/pull/27/files#diff-126888cfc483a0bf4a51486e84145f7b07150e75c1b28d252bf01b3f493aeba8" target="_blank">https://github.com/openjdk/amber-docs/pull/27/files#diff-126888cfc483a0bf4a51486e84145f7b07150e75c1b28d252bf01b3f493aeba8</a></div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">Thank you for your time and help!</div><div style="font-family:monospace" class="gmail_default">David Alayachew</div><br></div><div class="gmail_default" style="font-family:monospace"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 29, 2025 at 10:38 PM Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" target="_blank">archie.cobbs@gmail.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"><div dir="auto">Hi David,</div><div dir="auto"><br></div><div dir="auto">There was lots of discussion on amber-dev but it may be hard to track down. I am happy to dig up some of those threads and will follow up in a few days with some links for you.</div><div dir="auto"><br></div><div dir="auto">Thanks a lot for putting this FAQ together! I think it will be a great resource to have.</div><div dir="auto"><br></div><div dir="auto">-Archie</div><div dir="auto"><br clear="all"><div dir="auto"><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div></div><div><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Mar 29, 2025 at 7:30 PM David Alayachew <<a href="mailto:davidalayachew@gmail.com" target="_blank">davidalayachew@gmail.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"><div dir="ltr"><div style="font-family:monospace" class="gmail_default">Question for the group -- can anyone find any question about JEP 447/482/492 that might go into a FAQ?</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">I have been going through at least one feature a week, and I am on Flexible Constructor Bodies, and I can't find any questions people seem to have with it. I have scoured (to the best of my ability) Reddit and Amber Dev. I am going to go through Amber Spec Experts next, but just wanted to see if, either I missed something in Reddit/Amber Dev, or if someone has direct/private emails that capture some questions that are "FAQ".</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">And sorry to solo you out, but adding you directly <a class="gmail_plusreply" id="m_4088098373362859471m_8067662253295474282m_-8670675533367122853m_-1902532794640816799plusReplyChip-0" href="mailto:archie.cobbs@gmail.com" target="_blank">@Archie Cobbs</a>! Since you gave birth to this feature lol.</div><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">In the meantime, I'll add a super weak "Why do we need this feature?" to the FAQ, because that is the grand total of all that I could find for this featurefrom my search thus far. And tbf, I have good answers for it, it's just not that enticing of a question, and I feel like there are more questions I just haven't found.</div></div>
</blockquote></div></div>
</blockquote></div>
</blockquote></div><div><br clear="all"></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div>