Try-catch block injection

Nikolas Nehmer <[email protected]>
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
Hi,

I'm trying to do the following transformation based on bytecode injection:

startLabel:
foo...;
endLabel

into

try {
    startLabel:
    foo...;
    endLabel
} catch (VerifyError e) {
    //doSomething;
}

Currently, my code looks like this (raising a java.lang.ClassFormatError):

LabelNode startLabel = new LabelNode();
tempList.add(startLabel);
                   
LabelNode endLabel = new LabelNode();
tempList.add(endLabel);
                   
//catch block
int numberOfLocalVariables = 0;
Object[] localVariableTypes = new Object[0];
int numberOfStackElements = 0;
Object[] stackElementTypes = new Object[0];
tempList.add(new FrameNode(Opcodes.F_FULL, numberOfLocalVariables, 
localVariableTypes, numberOfStackElements, stackElementTypes));
tempList.add(new MethodInsnNode(Opcodes.INVOKESTATIC, 
logger,"testTryCatch", ("()V")));

list.insertBefore(currentInsnNode, tempList);
           
list.insert(new FrameNode(Opcodes.F_SAME, numberOfLocalVariables, 
localVariableTypes, numberOfStackElements, stackElementTypes));
tryCatchBlocks.add(new TryCatchBlockNode(startLabel, endLabel, endLabel, 
"java/lang/Throwable"));

Any suggestions?

Cheers
Nikolas
message-footer.txt (text/plain, 238 B)
-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.