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

Inside an anonymous inner class, how can this==Enclosing.this? (Modena:ciner066)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.0
    • 1.1.4
    • tools
    • None
    • 1.2fcs
    • generic
    • solaris_2.5.1
    • Not verified

      In this example, an anon local class is checking to see if the
      enclosing class instance IS the current instance. I don't understand
      how they can be the same. The bytecodes do not try and access the this$ field
      for Anonsense.this, and in fact the inner class Anonsense$1 doesn't even have
      one.

      If there is something here that is violating the spec, please let me know.
      [I know it violates clean coding rules. :^( ]

      cruella<134> cat Anonsense.java
      /* Isolated from Modena testcase ciner066. */
      public class Anonsense {
        void test() { /* Needed to compile, never Called */ int i = 0; i = 1/i; }
        void checkIt() {
             Anonsense z = new Anonsense() {
                  void test() {
                    if ( this == Anonsense.this ) {
                        /* This should not be true, how can the enclosing instance
                         * BE the current instance?
                         * Bytecodes look like:
                         * aload_0
                         * aload_0
                         * if_acmpne
                         * which seems to imply that it thinks these are the same.
                         */
                        System.out.println("HOW CAN THIS BE?");
                    }
                  }
             };
             z.test();
        }
        public static void main(String[] s) {
           Anonsense x = new Anonsense();
           x.checkIt();
        }
      }
      cruella<135> javac Anonsense.java && java -verify Anonsense
      HOW CAN THIS BE?


      -kto

      kelly.ohair@Eng 1998-01-07

            wmaddoxsunw William Maddox (Inactive)
            ohair Kelly Ohair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: