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

Javac allows access to fields not in scope from Anonymous class

XMLWordPrintable

    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_10-rc"
      Java(TM) SE Runtime Environment (build 1.6.0_10-rc-b28)
      Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP

      A DESCRIPTION OF THE PROBLEM :
        From JCK
      "ASSERTION clss360 - Anonymous class instance creation expression within explicit constructor invocation.

      ASSERTION
      If an anonymous class instance creation expression appears within an explicit constructor invocation statement, then the anonymous class may *not* refer to *any* of the enclosing instances of the class whose constructor is being invoked."

      Javac fails this test the actual implementation in JCK ensures that the compiler does the exact opposite!

      TEST clss36002 reads:
      "DESCRIPTION
      The test checks that it is *allowed* to refer to any of the enclosing instances of the class whose constructor is being invoked." (compiler positive)

      In the case of method calls JLS explicitly specifies a compile-time error

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile the test case

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The compilation should fail
      ACTUAL -
      It compiles without error

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class clss36002a {
          int a1 = 5;
          class a {
              a(Object o) {}
          }
          class c extends a {
      int c = 555;
              c() {
                  super(new Object() { int r = a1; } );
              }
          }
      }

      ---------- END SOURCE ----------

            mcimadamore Maurizio Cimadamore
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: