Using the BasicVerifier to verify methods, the information about errors is
currently not as useful as it could be, particularly because the instruction
numbers given do not reflect actual bytecode addresses or indexes (because it
is the rank of the faulty instruction in the method node's instruction list,
which includes labels, line number info, and so on).
I propose to include a reference to the faulty instruction in the
AnalyzerException class so that a more useful message can be generated by the
client code. The attached patch does precisely this. Then a code snippet like
this one can be used to retrieve the actual bytecode rank of an instruction,
which is very useful when using a tool that numbers the bytecodes, like eg.
jclasslib):
private int getBytecodeRank(MethodNode aNode, AbstractInsnNode aInstruction)
{
if (aInstruction == null) return -1;
int theRank = 1;
ListIterator<AbstractInsnNode> theIterator = aNode.instructions.iterator();
while(theIterator.hasNext())
{
AbstractInsnNode theNode = theIterator.next();
if (theNode == aInstruction) return theRank;
int theOpcode = theNode.getOpcode();
if (theOpcode >= 0) theRank++;
}
return -1;
}