fit INVOKEDYNAMIC

This commit is contained in:
金戟 2021-01-22 00:09:32 +08:00
parent 6951b98c7e
commit ef5d21baf6
3 changed files with 12 additions and 4 deletions

View File

@ -1,5 +1,9 @@
# Release Note
## 0.4.10
- fix an issue of using mock in lambda expression
- fix the NullPointerException when invoke private method with parameter value `null`
## 0.4.9
- fix an issue cause by improperly bytecode processing while using `targetClass` parameter
- auto validate access target of `PrivateAccessor`, improve resistance to code refactoring

View File

@ -1,5 +1,9 @@
# Release Note
## 0.4.10
- 修复在Lambda函数中使用Mock出错的BUGissue-44
- 修复调用私有方法时参数值不能为null的问题issue-27
## 0.4.9
- 修复发起调用的对象不是局部或成员变量时Mock出错的BUG (issue-40)
- 增加`PrivateAccessor`访问目标有效性检查,提高抗代码重构能力 (issue-21)

View File

@ -175,10 +175,11 @@ public class SourceClassHandler extends BaseClassHandler {
case Opcodes.INVOKESPECIAL:
case Opcodes.INVOKEVIRTUAL:
case Opcodes.INVOKEINTERFACE:
return stackEffectOfInvocation(instruction) + 1;
return stackEffectOfInvocation(((MethodInsnNode)instruction).desc) + 1;
case Opcodes.INVOKESTATIC:
return stackEffectOfInvocation(((MethodInsnNode)instruction).desc);
case Opcodes.INVOKEDYNAMIC:
return stackEffectOfInvocation(instruction);
return stackEffectOfInvocation(((InvokeDynamicInsnNode)instruction).desc);
case -1:
// either LabelNode or LineNumberNode
return 0;
@ -187,8 +188,7 @@ public class SourceClassHandler extends BaseClassHandler {
}
}
private int stackEffectOfInvocation(AbstractInsnNode instruction) {
String desc = ((MethodInsnNode)instruction).desc;
private int stackEffectOfInvocation(String desc) {
return ClassUtil.getParameterTypes(desc).size() - (ClassUtil.getReturnType(desc).isEmpty() ? 0 : 1);
}