JDK-8073618 : Cannot assign a value to final variable in lambda if it is in enum entry/const
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u31
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-02-09
  • Updated: 2015-11-23
  • Resolved: 2015-11-23
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Related to https://bugs.openjdk.java.net/browse/JDK-8051958
If lambda is used as part of enum entry, then bug still occur.
This same code without enum (but still with lambda) works fine.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just create enum with any FunctionalInterface as any of args.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error:(9, 13) java: cannot assign a value to final variable bug

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Main {
    public enum Bugs {
        BUG_ONE(() -> {
            final Boolean bug;
            bug = true;
        });
        private final Runnable runnable;
        Bugs(final Runnable runnable) {
            this.runnable = runnable;
        }
    }
    public static void main(final String[] nope) {
        Bugs.BUG_ONE.runnable.run();
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
compile it with eclipse compiler.

SUPPORT :
YES


Comments
Closing this as duplicate of JDK-8051958
23-11-2015

Checked this for JDK 8u25, 8u31 and could rerproduce the issue from command line and Netbeans. The code compiled fine with Eclipse though. Tested this for JDK 8u40 b23 and JDK 9 b50 and test case compiled fine. Closing this as duplicate of JDK-8051958 which has issues resolved fixed from JDK 8u40 b06 and JDK 9 b26.
23-02-2015