Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looks good! keep working! #1

Closed
hydraxman opened this issue Mar 6, 2017 · 1 comment
Closed

Looks good! keep working! #1

hydraxman opened this issue Mar 6, 2017 · 1 comment

Comments

@hydraxman
Copy link

at stack depth 0, expected type java.lang.Object but found int
这个问题似乎不是你调用方法传参的问题,而是你使用aload指令操作的栈上的数据类型不对,似乎应该使用iload

@hydraxman hydraxman changed the title Looks good, keeping working! Looks good, keep working! Mar 6, 2017
@hydraxman hydraxman changed the title Looks good, keep working! Looks good! keep working! Mar 6, 2017
@nailperry-zd
Copy link
Owner

问题解决了

  • visitInsn尾部插入代码出错:at stack depth 0, expected type java.lang.Object but found int

注入的方法描述:(Ljava/lang/Object;Z)V

for (def i = methodCell.paramsStart; i < methodCell.paramsStart + methodCell.paramsCount; i++) {
    // Todo: 这里直接传入i居然报错:at stack depth 0, expected type java.lang.Object but found int;强制转换成Object才行。why?
    methodVisitor.visitVarInsn(Opcodes.ALOAD, i);
}

// 改写成如下代码依然报错
methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
if (methodCell.paramsCount == 2) {
    methodVisitor.visitVarInsn(Opcodes.ILOAD, 1);
}
methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, ReWriterConfig.sAgentClassName, methodCell.agentName, methodCell.agentDesc, false);

出错原因:

代码执行时,输入的方法描述实际为(Ljava/lang/Object;)V,只接收一个参数,而methodCell.paramsCount仍为2,导致methodVisitor.visitVarInsn指令加载了两次。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants