JDK-4717190 : don't allow a local class in a switch to capture a variable form the switch
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_8
  • CPU: generic
  • Submitted: 2002-07-18
  • Updated: 2002-08-13
  • Resolved: 2002-08-13
Related Reports
Duplicate :  
Description
javac fails the jacks test 16.2.3-switch-1.  The offending code is something
like

        void f(int n) {
            switch (n) {
              case 12:
                final int x;
                x = 1;
                class Local {
                    int y = x;
                }
                break;
              case 13:
                int z = new Local().y; // verify error in generated code
            }
        }

The problem is that the JLS allows this code, but the variable x hasn't
been assigned at the point where it is captured.

Comments
EVALUATION Suggestion is to not allow capturing a switch local variable in a switch local class. ###@###.### 2002-07-18
18-07-2002