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

com.sun.jdi.ReferenceType.nestedTypes() returns bad data for inner classes

XMLWordPrintable

    • x86
    • linux



      Name: tb29552 Date: 03/28/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)


      Create a class with inner classes as in the example at the bottom of this test.

      When you try to retrieve nested types of the outer class, the method
      "nestedTypes()" returns not only the named inner class of the outer class but
      also the anonymous inner class of the named inner class:

          OuterClass.nestedTypes() = [
               OuterClass$1
               OuterClass$InnerClass
          ]

      And if you try to get nested types of the named inner class, the method
      "nestedTypes()" returns an empty list:

          OuterClass$InnerClass.nestedTypes() = []

      I think that this is caused by Javac because it produces strange .class files:

          OuterClass
          OuterClass$1
          OuterClass$InnerClass

      FastJavac produces another .class files for the same sources:

          OuterClass
          OuterClass$InnerClass
          OuterClass$InnerClass$1

      But the "nestedTypes()" method does not work well even if you compile sources
      with FastJavac. It then correctly recognizes the anonymous inner class to be the
      nested type of the named InnerClass:

          OuterClass$InnerClass.nestedTypes = [
               OuterClass$InnerClass$1
          ]

      but it still returns bad data because - it returns also nested types of nested
      types:

          OuterClass.nestedTypes = [
               OuterClass$InnerClass
               OuterClass$InnerClass$1
          ]

      -----------------------------------------------------------------
      Source code example follows...
      -----------------------------------------------------------------

      package test;

      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      public class OuterClass {

          class InnerClass {

              ActionListener anonymouslistener = new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      System.out.println("Action performed!");
                  }
              };

          }

          public void test() {
              InnerClass innerClass1 = new InnerClass(); //Loads all classes.

              //
              // Try to retrieve nestedTypes of the OuterClass.
              //
          }

          public static void main(String args[]) {
              new OuterClass().test();
          }

      }
      (Review ID: 119682)
      ======================================================================

            Unassigned Unassigned
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: