[英]Alter method access to an argument using bytebuddy
I have a case like the example below 我有一个类似下面的例子
public String test(Trail trail) {
AnotherClass.access(trail);
this.executeAnotherMethod(trail);
futureCall(trail::end);
return "emptyString";
}
And I want to use byte-buddy to do something like this 我想使用字节伙伴来做这样的事情
public String test(Trail trail) {
Trail clonedTrail = trail.clone("test");
AnotherClass.access(clonedTrail);
this.executeAnotherMethod(clonedTrail);
futureCall(clonedTrail::end);
return "emptyString";
}
I have tried Advice
to intercept the call but that messed up object reference. 我已经尝试过
Advice
拦截该调用,但是这弄乱了对象引用。 I have been diving through byte-buddy testcases as well as reading ASM, but haven't made great progress so far. 我一直在研究字节预算测试用例以及阅读ASM,但到目前为止还没有取得很大的进步。
This can be done with advice by overwriting the argument. 这可以通过覆盖参数的建议来完成。
@Advice.OnMethodEnter
static void enter(@Advice.Argument(readOnly = false) Trail trail) {
trail = trail.clone("test");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.