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

NoClassdefFound when anonymously extending a class

XMLWordPrintable

    • b114
    • generic, x86
    • generic, linux, windows_xp
    • Verified

      FULL PRODUCT VERSION :
      Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)

      Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP

      A DESCRIPTION OF THE PROBLEM :
      When you anonymously extend a class that is selectively instantiated at runtime i get a NoClassDefFound error. I have created a simple example that shows the simlpest form to recreate.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Using a tenaory operator to selectively initialise a static variable

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      print Hello
      ACTUAL -
      Exception in thread "main" java.lang.NoClassDefFoundError: Test$1

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;

      public class Test
      {
      private static final ArrayList<String> list = true ? null : new ArrayList<String>() { };

      public static void main(String[] args)
      {
      System.out.println("Hello");
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      don't use ternary operator to create static class, use a static intialiser.

            sundar Sundararajan Athijegannathan
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: