mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-03-13 03:10:34 +08:00
local variable table of non-static method can be empty
This commit is contained in:
parent
31140bef87
commit
d463f863db
@ -101,7 +101,8 @@ public class MockClassHandler extends BaseClassWithContextHandler {
|
||||
// must get label before method description changed
|
||||
ImmutablePair<LabelNode, LabelNode> labels = getStartAndEndLabel(mn);
|
||||
mn.desc = MethodUtil.addParameterAtBegin(mn.desc, targetClassName);
|
||||
int parameterOffset = MethodUtil.isStatic(mn) ? 0 : 1;
|
||||
// in certain case, local variable table of non-static method can be empty (issue-136)
|
||||
int parameterOffset = MethodUtil.isStatic(mn) ? 0 : Math.min(mn.localVariables.size(), 1);
|
||||
mn.localVariables.add(parameterOffset, new LocalVariableNode(SELF_REF, targetClassName, null,
|
||||
labels.left, labels.right, parameterOffset));
|
||||
for (int i = parameterOffset + 1; i < mn.localVariables.size(); i++) {
|
||||
@ -123,6 +124,7 @@ public class MockClassHandler extends BaseClassWithContextHandler {
|
||||
}
|
||||
|
||||
private ImmutablePair<LabelNode, LabelNode> getStartAndEndLabel(MethodNode mn) {
|
||||
// in certain case, local variable table of non-static method can be empty (issue-136)
|
||||
if (MethodUtil.isStatic(mn) || mn.localVariables.isEmpty()) {
|
||||
LabelNode startLabel = null, endLabel = null;
|
||||
for (AbstractInsnNode n = mn.instructions.getFirst(); n != null; n = n.getNext()) {
|
||||
|
Loading…
Reference in New Issue
Block a user