Java 8 ClassFormatException for interface with static methods, but only when using assertions

I started getting ClassFormatExceptions that I couldn't explain related to interfaces with static methods. I trimmed it down to this test case:

public interface ModifierTest
{
    public static final int DELTA = 10;

    public static int increment(int value)
    {
        assert value > 0; // Problem line
        return value + DELTA;
    }
}

public class ModifierExec
{
    public static void main(String[] args)
    {
        System.out.println(ModifierTest.class);
    }
}

      

Without an assertion in the increment () method, everything is fine. But with the assertion, I am getting a runtime exception (compilation is fine):

Exception in thread "main" java.lang.ClassFormatError: Illegal field modifiers in class ModifierTest: 0x1018
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.c4.camgen.ModifierExec.main(ModifierExec.java:7)

      

It's easy to work with, but I'm curious if this is a bug in Java or the correct (if weird) behavior. I can't find any references to assertions affecting field modifiers.

Can anyone tell me what's going on? Running in Eclipse Kepler under jdk 1.8.0_20.

+3


source to share


1 answer


First of all, Eclipse has its own compiler, so there is a possible bug, not in javac

.

Juno is now an older version that predates Eclipse support for Java 8, and earlier Java versions did not allow static methods in an interface at all. This is where your report gets confused.



Either way, you should upgrade to Luna to work seamlessly with Java 8 in Eclipse.

+3


source







All Articles