CheckMethodAdapter.visitMaxs() doesn't take ClassWriter.COMPUTE_FRAMES into account
If you use a ClassWriter with ClassWriter.COMPUTE_FRAMES to auto calculate the
max stack size, and you have code like this:
ClassWriter classWriter = new ClassWriter(classReader,
ClassWriter.COMPUTE_FRAMES);
classReader.accept(new MyClassInstrumentor(new
CheckClassAdapter(classWriter)), ClassReader.EXPAND_FRAMES);
return classWriter.toByteArray();
in your custom method instrumentor when you do this:
@Override
public void visitMaxs(int maxStack, int maxLocals)
{
//perfectly valid, since due to expand_frames i can pass in anything
here
super.visitMaxs(0, 0);
}
the CheckMethodAdapater will throw an exception, because it does expect the
exact stack size.
com.chronon.apm.libs.org.objectweb.asm.tree.analysis.AnalyzerException: Error
at instruction 0: Insufficient maximum stack size.
at
com.chronon.apm.libs.org.objectweb.asm.tree.analysis.Analyzer.analyze(Unknown
Source)
at
com.chronon.apm.libs.org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unkno
wn Source)
at
com.chronon.apm.libs.org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source)
at
com.chronon.apm.libs.org.objectweb.asm.util.CheckMethodAdapter.visitEnd(Unknown
Source)
at
com.chronon.apm.libs.org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source)
at com.chronon.apm.libs.org.objectweb.asm.ClassReader.b(Unknown Source)