<div dir="ltr"><div>Hi Maurizio,</div><div><br></div><div>Please see <a href="https://github.com/openjdk/jdk/compare/master...archiecobbs:jdk:dummy-variable-detector?expand=1">https://github.com/openjdk/jdk/compare/master...archiecobbs:jdk:dummy-variable-detector?expand=1</a></div><div><br></div><div>I made it a note instead of a warning so that builds would not be artificially halted.</div><div><br></div><div>Here's an example:</div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">$ cat Test.java<br></span></div><div style="margin-left:40px"><span style="font-family:monospace">class Test {<br>    {<br>        for (int i = 1; i <= 3; i++) {<br>            int i2 = i;<br>            Runnable r = () -> System.out.println(i2);<br>        }<br>    }<br>}</span></div><div style="margin-left:40px"><span style="font-family:monospace">$ javac Test.java</span></div><div style="margin-left:40px"><span style="font-family:monospace">flex-test/Test.java:4: Note: detected effectively final "dummy variable" i2<br>            int i2 = i;<br>                ^</span></div><div>I *think* the logic is accurate but it could probably use a quick review.<br></div><div><br></div><div>-Archie<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 16, 2024 at 9:11 AM Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com">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="ltr"><div>Hi Maurizio,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 16, 2024 at 8:56 AM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" target="_blank">maurizio.cimadamore@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"><u></u>

  
  <div>
    <div><p style="margin:0px 0px 1.2em">Could you come up
        with a javac patch that detects such “dummy” variable
        declarations and prints a note/warning in the compiler output?</p></div></div></blockquote><div>Excellent idea - I agree this is something worth further exploration to better understand.<br></div><div><br></div><div>I will work on it and report back.<br></div><div><br></div><div>-Archie<br></div><div><br></div></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>
</blockquote></div><br clear="all"><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div>