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

Javac produces dead anonymous inner classes

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.2.1
    • tools
    • beta
    • x86
    • windows_nt
    • Verified



      Name: skT88420 Date: 05/17/99


      The javac compiler produces class files for anonymous inner
      classes even when those classes are contained in blocks of
      dead code. Since these classes can never be instantiated,
      they only consume space which is a big concern for applet
      developers. Consider the following class:

      // DeadClass.java

      class DeadClass {
          static final boolean ALIVE = false;
          
          void someMethod() {
              if (ALIVE) {
                  // This block is dead since ALIVE evaluates to the
                  // constant "false" at compile time.
                  Object o = new Object() {
                      void anotherMethod() { }
                  };
              }
          }
      }

      Compiling the above source file creates the files "DeadClass.class"
      and "DeadClass$1.class". However, a quick inspection of the byte
      codes using "javap -c DeadClass" reveals that DeadClass$1 is never
      instantiated. The compiler should remove this class as part of
      its dead code elimination.
      (Review ID: 83164)
      ======================================================================

            busersunw Btplusnull User (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: