I started to get ClassFormatExceptions I couldn't explain relating to interfaces with static methods. I pruned 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 the assertion in the increment() method, everything is fine. But with the assertion, I get an exception at run time (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)
This is easy to work round, but I'm curious as to whether this is a bug in Java or correct (if strange) behaviour. 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.