Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8335190

local class creation expression should take into account captured local variables

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 24
    • None
    • specification
    • master

      Consider this program:

      class StaticNewInnerTest {
              public static void main(String[] args) {
                  class Local1 {
                      { System.out.println(args); }
                  }
                  class Local2 {
                      static Local1 x = new Local1(); // 1
                  }
              }
          }

      The local class creation in (1) is problematic: it occurs in a context where we no longer have access to the local variable that are captured by Local1 (namely "args").

      JLS 15.9.2 has some rules around local class creation, but they are too weak to detect cases like this. Note also how this is a "new" problem, as it used not to be ok to declare static members inside local classes.

            gbierman Gavin Bierman
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: