<div dir="ltr"><div>I'd encourage them to flatten the if-else chain when true-bodies don't complete normally (throwing or returning)</div><div><br></div><div><span style="font-family:monospace">
static void ensureCapacity(List l) {<br>  if (l instanceof LinkedList) {<br>    throw new IllegalArgumentException("Use an efficient list implementation");<br>  }</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">  if (!(l instanceof ArrayList al)) {<br>    return;<br>  }<br>  al.ensureCapacity(10);<br>  System.out.println("done");<br>}</span></div><div> </div><div>This is, IMO, simpler to read and reason about.  Simply some number of 'gates' to pass before reaching the work of the method.</div><div><br></div><div>And as you add new gates, you don't create churn on the lines for the other gates (thinking about simpler diffs and clearer git-blame information).</div><div><br></div><div>--</div><div>Aaron Scott-Boddendijk</div><div><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, 9 Jun 2025 at 20:34, Jean-Noël Rouvignac <<a href="mailto:jean-noel.rouvignac@pingidentity.com">jean-noel.rouvignac@pingidentity.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"><div>Yes, I can now see how this matches the spec, and it makes sense.</div><div dir="auto">Although this could perhaps be a bit surprising to the users, I believe the workarounds make for better code anyway.</div><div dir="auto"><br></div><div dir="auto">This reminds me of another case discussed some time ago: effectively final assignment over try / catch. It is the same thing here: trying to go above and beyond for edge cases can trigger more problems down the line, so we're better off not doing it.</div><div dir="auto"><br></div><div dir="auto">Thanks a lot to all of you for taking the time to answer.</div><div dir="auto"><br></div><div dir="auto">Jean-Noël</div><div><table style="border-collapse:collapse;padding:0px;margin:0px"><tbody><tr><td colspan="2"><br></td></tr></tbody></table></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le lun. 9 juin 2025 à 08:12, Jan Lahoda <<a href="mailto:jan.lahoda@oracle.com" target="_blank">jan.lahoda@oracle.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>

  
  <div>
    <p>Hi,</p>
    <p><br>
    </p>
    <p>I believe this is what is specified.</p>
    <p><br>
    </p>
    <p>Considering:</p>
    <p>if (e) S</p>
    <p>else T</p>
    <p><br>
    </p>
    <p>JLS 6.3.2.2, says that (in some cases), the binding variable from
      'e' can be introduced to the enclosing scope of the `if`. But I am
      not aware about anything that would say a variable from `T` should
      be introduced to the enclosing scope if the outer `if`.</p>
    <p><br>
    </p>
    <p>In the example below, `if (l instanceof LinkedList)` does not
      introduce any binding variables, and hence no binding variable is
      not introduced to the enclosing scope of the `if`.<br>
    </p>
    <p><br>
    </p>
    <p>Please also see:<br>
    </p>
    <p><a href="https://bugs.openjdk.org/browse/JDK-8335402" rel="noreferrer" target="_blank">https://bugs.openjdk.org/browse/JDK-8335402</a></p>
    <p><br>
    </p>
    <p>Jan</p>
    <p><br>
    </p>
    <div>On 07. 06. 25 16:55, David Alayachew
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="auto">
        <p dir="ltr">This definitely looks like a bug. Maybe some of the
          amber folks are busy with Valhalla or something, but I can't
          see this NOT being a bug.</p>
        <p dir="ltr"><span class="gmail_chip gmail_plusreply" dir="auto"><a href="mailto:angelos.bimpoudis@oracle.com" style="color:rgb(17,85,204);text-decoration:underline" rel="noreferrer noreferrer" target="_blank">@Angelos
              Bimpoudis</a></span><span> poke poke poke</span></p>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Sat, Jun 7, 2025, 3:14 AM
          Jean-Noël Rouvignac <<a href="mailto:jean-noel.rouvignac@pingidentity.com" rel="noreferrer noreferrer noreferrer" target="_blank">jean-noel.rouvignac@pingidentity.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>Hello folks,</div>
            <div><br>
            </div>
            <div>JDK 25 rampdown phase 1 is now behind us, congrats and
              thanks for all the work done to get there!
              <div><br>
              </div>
              I am reviving this use case to see if anyone agrees that
              this may be a bug?<br>
              <br>
            </div>
            <div>Thank you,</div>
            <div>Jean-Noel</div>
            <div><br>
            </div>
          </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">On Wed, Apr 16, 2025 at
              11:37 AM Jean-Noël Rouvignac <<a href="mailto:jean-noel.rouvignac@pingidentity.com" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">jean-noel.rouvignac@pingidentity.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>
                  <div>
                    <div>
                      <div>Hello amber-dev folks!<br>
                        <br>
                      </div>
                      <div>While using pattern matching for instanceof I
                        noticed a small incoherent oddity.<br>
                      </div>
                      <div><br>
                      </div>
                      <div>Take this code:</div>
                      <div>```<br>
                        static void ensureCapacity(List l) {<br>
                          if (l instanceof LinkedList) {<br>
                            throw new IllegalArgumentException("Use an
                        efficient list implementation");<br>
                          } else if (!(l instanceof ArrayList al)) {<br>
                            return;<br>
                          }<br>
                          al.ensureCapacity(10);<br>
                          System.out.println("done");<br>
                        }<br>
                        <br>
                        ensureCapacity(new ArrayList());</div>
                      ```<br>
                      <br>
                      The compiler rejects this code with: `Cannot
                      resolve symbol 'al'`.<br>
                      (I have tested that code with JDK 24 in the
                      playground (<a href="https://dev.java/playground" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">https://dev.java/playground</a>)
                      but also in my IDE with JDK 21)<br>
                      <br>
                    </div>
                    However #1, removing the `else` keyword makes the
                    code successfully compile:<br>
                    ```<br>
                      }</div>
                  <div>  if (!(l instanceof ArrayList al)) {<br>
                        return;<br>
                      }</div>
                  <div>```<br>
                    <br>
                    However #2, adding an additional `else` keyword
                    makes the code successfully compile:<br>
                    ```<br>
                            } else if (!(l instanceof ArrayList al)) {<br>
                                return;<br>
                            } else {<br>
                                al.ensureCapacity(10);<br>
                                System.out.println("done");<br>
                            }</div>
                  <div>```<br>
                  </div>
                  <div><br>
                  </div>
                  <div>While option #1 and #2 are acceptable
                    workarounds, it looks to me like there could be a
                    bug in javac? Therefore I am bringing this to your
                    attention so you can decide if it is a bug or not.</div>
                  <div><br>
                  </div>
                  I searched the JDK's bug tracker for this specific
                  case, but could not find anything related.<br>
                  <br>
                </div>
                <div>Thanks!</div>
                <div>Jean-Noël</div>
              </div>
            </blockquote>
          </div>
          <div><br clear="all">
          </div>
          <br>
          <span class="gmail_signature_prefix">-- </span><br>
          <div dir="ltr" class="gmail_signature">
            <table style="border-collapse:collapse;padding:0px;margin:0px">
              <tbody>
                <tr>
                  <td style="width:113px"><a href="https://www.pingidentity.com/" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank"><img alt="Ping Identity"></a></td>
                  <td>
                    <table>
                      <tbody>
                        <tr>
                          <td style="vertical-align:top"><span style="color:rgb(230,29,60);display:inline-block;margin-bottom:3px;font-family:arial,helvetica,sans-serif;font-weight:bold;font-size:14px">Jean-Noel
                              Rouvignac</span><br>
                            <span style="display:inline-block;margin-bottom:2px;font-family:arial,helvetica,sans-serif;font-size:14px">Senior
                              Principal Software Engineer</span><br>
                            <span style="font-family:arial,helvetica,sans-serif;font-size:14px;display:inline-block;margin-bottom:3px"><font color="#1530f9"><a href="mailto:jean-noel.rouvignac@pingidentity.com" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">jean-noel.rouvignac@pingidentity.com</a></font><br>
                              <span style="display:inline-block;margin-bottom:2px"></span><br style="font-family:Times;font-size:medium">
                              <span style="display:inline-block;margin-bottom:2px"></span></span></td>
                        </tr>
                      </tbody>
                    </table>
                  </td>
                </tr>
                <tr>
                  <td colspan="2">
                    <table style="border-collapse:collapse;border:medium;margin:8px 0px 0px;width:408.938px">
                      <tbody>
                        <tr style="height:40px;border-top:1px solid rgb(211,211,211);border-bottom:1px solid rgb(211,211,211)">
                          <td style="font-family:arial,helvetica,sans-serif;font-size:14px;font-weight:bold;color:rgb(64,71,75)"><a href="https://www.pingidentity.com/en/events/youniverse.html" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank"><img style="height: 106px; width: 410px;"></a><br>
                            <div style="padding:0px;margin:0px">
                              <table style="border-collapse:collapse;padding:0px;margin:0px">
                                <tbody>
                                  <tr>
                                    <td colspan="2">
                                      <table style="border-collapse:collapse;border:medium;margin:8px 0px 0px;width:408.938px">
                                        <tbody>
                                          <tr style="height:40px;border-top:1px solid rgb(211,211,211);border-bottom:1px solid rgb(211,211,211)">
                                            <td style="font-size:14px;font-weight:bold;color:rgb(64,71,75)">Connect with
                                              us:</td>
                                            <td style="padding:4px 0px 0px 20px"><a href="https://www.glassdoor.com/Overview/Working-at-Ping-Identity-EI_IE380907.11,24.htm" title="Ping on Glassdoor" style="margin-right:16px;display:inline-block" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank"><img alt="Glassdoor logo" style="border: medium; margin: 0px; display: inline-block;"></a><a href="https://www.linkedin.com/company/21870" title="Ping on LinkedIn" style="margin-right:16px;display:inline-block" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank"><img alt="LinkedIn logo" style="border: medium; margin: 0px; display: inline-block;"></a><a href="https://twitter.com/pingidentity" title="Ping on Twitter" style="margin-right:16px" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank"><img alt="Twitter logo" style="border: medium; margin: 0px; display: inline-block;"></a><a href="https://www.youtube.com/user/PingIdentityTV" title="Ping on YouTube" style="margin-right:16px;display:inline-block" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank"><img alt="YouTube logo" style="border: medium; margin: 0px; display: inline-block;"></a><a href="https://www.pingidentity.com/en/blog.html" title="Ping Blog" style="margin-right:16px;display:inline-block" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank"><img alt="Blog logo" style="border: medium; margin: 0px;"></a></td>
                                          </tr>
                                        </tbody>
                                      </table>
                                    </td>
                                  </tr>
                                </tbody>
                              </table>
                              <div style="padding:0px;margin:0px"><span style="font-family:Arial,sans-serif;font-size:12px"><font color="#787878">To view our privacy
                                    policy, click </font><a href="https://www.pingidentity.com/en/legal/privacy.html" style="text-decoration:underline" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank"><font color="#1255cd">here</font></a><br>
                                </span></div>
                              <div style="padding:0px;margin:0px"><span style="font-family:Arial,sans-serif;font-size:12px"><font color="#787878">To stop receiving
                                    these emails, click </font><a href="https://4.pingidentity.com/PreferenceCenter.html" style="text-decoration:underline" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank"><font color="#1255cd">here</font></a></span></div>
                            </div>
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
          <br>
          <i style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background:rgb(255,255,255);font-family:proxima-nova-zendesk,system-ui,-apple-system,system-ui,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",Arial,sans-serif;color:rgb(85,85,85)"><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background:transparent;font-family:proxima-nova-zendesk,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",Arial,sans-serif;font-weight:600"><font size="2">CONFIDENTIALITY NOTICE: This email may contain
                confidential and privileged material for the sole use of
                the intended recipient(s). Any review, use, distribution
                or disclosure by others is strictly prohibited.  If you
                have received this communication in error, please notify
                the sender immediately by e-mail and delete the message
                and any file attachments from your computer. Thank you.</font></span></i></blockquote>
      </div>
    </blockquote>
  </div>

</blockquote></div>

<br>
<i style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background:rgb(255,255,255);font-family:proxima-nova-zendesk,system-ui,-apple-system,system-ui,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",Arial,sans-serif;color:rgb(85,85,85)"><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background:transparent;font-family:proxima-nova-zendesk,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",Arial,sans-serif;font-weight:600"><font size="2">CONFIDENTIALITY NOTICE: This email may contain confidential and privileged material for the sole use of the intended recipient(s). Any review, use, distribution or disclosure by others is strictly prohibited.  If you have received this communication in error, please notify the sender immediately by e-mail and delete the message and any file attachments from your computer. Thank you.</font></span></i></blockquote></div>