Incorrect stackmap generated seems related to switch and Object[][]
Hi,
We are seeing an invalid stackmap frame being generated and have narrowed down
the reproducer to a fairly simple class along these lines:
import java.math.BigDecimal;
public class SimpObjRet {
public static void main(String [] args) {
try {
makeJavaArray(20, 7);
} catch(Exception e) {
e.printStackTrace();
}
}
public static Object[] makeJavaArray(int i, int j) throws Exception {
Object [] obj = null;
switch(j) {
case 7:
obj = new BigDecimal[i];
break;
case 12:
obj = new String[i];
break;
case -2:
obj = new byte[i][];
break;
default:
throw new Exception("failed");
}
return obj;
}
}
Simply reading the class and writing computing the frames is enough to show
this:
ClassReader cr = new ClassReader(bytes);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
cr.accept(cw, ClassReader.SKIP_FRAMES);
out = cw.toByteArray();
In the resulting class bytes what we see is an initial append frame with an
Opcode.NULL which looks odd, but may not itself be an issue. But at the end of
the method just before the ALOAD we see a full frame which has
a "java/lang/Object" for the local rather than a "[java/lang/Object". That
seems to be the frame that the verifier is unhappy with.
For example:
mv.visitFrame(Opcodes.F_FULL, 3, new Object[] {Opcodes.INTEGER,
Opcodes.INTEGER, "java/lang/Object"}, 0, new Object[] {});
I'm attaching a zip with a reproducer as well. The zip has files from my run
locally (before/after classes), but you can unzip and run it, the "ant"
default should build/run it
thanks
Tony