JDK-8300691 - final variables in for loop headers should accept updates

Archie Cobbs archie.cobbs at gmail.com
Wed Oct 16 20:44:40 UTC 2024


Hi Maurizio,

Please see
https://github.com/openjdk/jdk/compare/master...archiecobbs:jdk:dummy-variable-detector?expand=1

I made it a note instead of a warning so that builds would not be
artificially halted.

Here's an example:

$ cat Test.java
class Test {
    {
        for (int i = 1; i <= 3; i++) {
            int i2 = i;
            Runnable r = () -> System.out.println(i2);
        }
    }
}
$ javac Test.java
flex-test/Test.java:4: Note: detected effectively final "dummy variable" i2
            int i2 = i;
                ^
I *think* the logic is accurate but it could probably use a quick review.

-Archie

On Wed, Oct 16, 2024 at 9:11 AM Archie Cobbs <archie.cobbs at gmail.com> wrote:

> Hi Maurizio,
>
> On Wed, Oct 16, 2024 at 8:56 AM Maurizio Cimadamore <
> maurizio.cimadamore at oracle.com> wrote:
>
>> Could you come up with a javac patch that detects such “dummy” variable
>> declarations and prints a note/warning in the compiler output?
>>
> Excellent idea - I agree this is something worth further exploration to
> better understand.
>
> I will work on it and report back.
>
> -Archie
>
> --
> Archie L. Cobbs
>


-- 
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20241016/0a988d71/attachment-0001.htm>


More information about the amber-dev mailing list