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

java.lang.ClassFormatError: Illegal field modifiers in class (...)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • 8
    • tools
    • b113
    • windows_8
    • Verified

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0-ea"
      Java(TM) SE Runtime Environment (build 1.8.0-ea-lambda-nightly-h109-20130902-b10
      6-b00)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b45, mixed mode)
      First observed build 104, persisted after upgrade to 109

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.2.9200] (Windows 8 64Bit)

      A DESCRIPTION OF THE PROBLEM :
      The following simple Program, using an assert statement within an interface default method:

      package bug;

      public class Jdk8Bug {
          public interface B {
              default void m() {
                  assert "x" != null;
              }
          }

          static class A implements B {
          }

          public static void main(String[] args) {
              A x = new A();
          }

      }

      produces upon execution:

      Exception in thread "main" java.lang.ClassFormatError: Illegal field modifiers in class bug/Jdk8Bug$B: 0x1018
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:752)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:448)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:70)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:360)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:353)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:752)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:448)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:70)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:360)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:353)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
      at bug.Jdk8Bug.main(Jdk8Bug.java:16)
      Java Result: 1



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Just copy the above code, compile and go.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      assert should work as expected in default methods
      ACTUAL -
      Fails with Stacktrace

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ClassFormatError: Illegal field modifiers in class bug/Jdk8Bug$B: 0x1018
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:752)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:448)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:70)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:360)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:353)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:752)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:448)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:70)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:360)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:353)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
      at bug.Jdk8Bug.main(Jdk8Bug.java:16)
      Java Result: 1

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package bug;

      public class Jdk8Bug {

          public interface B {

              default void m() {
                  assert "x" != null;
              }

          }

          static class A implements B {
          }

          public static void main(String[] args) {
              A x = new A();
          }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't use assert within default methods

      Attachments

        Activity

          People

            jlahoda Jan Lahoda
            mcastegr Mattis Castegren (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: