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

java.lang.NoClassDefFoundError exception on running fully legitimate code

XMLWordPrintable

    • b16
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      x86/windows 10/ openjdk 19.0.1

      A DESCRIPTION OF THE PROBLEM :
      Getting java.lang.NoClassDefFoundError exception on running fully legitimate code

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run this snippet

      public interface Main {

      @interface Annotation {
      interface foo {
      static void print() {System.out.println("Oops!");}
      }

      @interface Foo {}
      }

      static void main(String[] args) {
      Annotation.foo.print();
      }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
       Ooops in the console
      ACTUAL -
      Exception in thread "main" java.lang.NoClassDefFoundError: Main$Annotation$Foo (wrong name: Main$Annotation$foo)
      at java.base/java.lang.ClassLoader.defineClass1(Native Method)
      at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
      at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
      at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
      at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
      at Main.main(Main.java:13)

      ---------- BEGIN SOURCE ----------
      public interface Main {

      @interface Annotation {
      interface foo {
      static void print() {System.out.println("Oops!");}
      }

      @interface Foo {}
      }

      static void main(String[] args) {
      Annotation.foo.print();
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      rename foo or Foo to something else

            acobbs Archie Cobbs
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: