I am working on code that computes entries in a StackFrameMap (SFM). The goal is to be able to generate records (SFMs) that make the Java 7 bytecode verifier happy. Following the TDD methodology, I started by creating dummy SMF entries for the verifier to complain; I would replace them with my correctly calculated entries to see that I am doing this correctly.
The problem is this: I can't get the bytecode verifier to complain. Here is an example starting with Java source code (this code should not do anything useful):
public int stackFrameTest(int x) { if (x > 0) { System.out.println("positive x"); } return -x; }
This generates the following bytecode (with SFM):
public int stackFrameTest(int); flags: ACC_PUBLIC Code: stack=2, locals=2, args_size=2 0: iload_1 1: ifle 12 4: getstatic #47
Now I am modifying SFM to contain this:
StackMapTable: number_of_entries = 1 frame_type = 255 offset_delta = 12 locals = [ double, float ] stack = [ double ]
As you can see, this is completely fictitious, but it loads without errors. I read the JVM specification and I could not understand why this would work. I do not use the SplitBytecodeVerifier parameter.
EDIT . According to the accepted answer below, Eclipse was configured to release Java 6 class files (version 50.0). Classfiles of this version will quietly ignore issues with StackFrameMap. After changing the setting to use the standard Java 7 style file (51.0), it worked as expected.
java bytecode bytecode-manipulation
Charles Forsythe
source share