java - 使用 bytebuddy 更改对参数的方法访问
问题描述
我有一个类似下面例子的案例
public String test(Trail trail) {
AnotherClass.access(trail);
this.executeAnotherMethod(trail);
futureCall(trail::end);
return "emptyString";
}
我想用 byte-buddy 做这样的事情
public String test(Trail trail) {
Trail clonedTrail = trail.clone("test");
AnotherClass.access(clonedTrail);
this.executeAnotherMethod(clonedTrail);
futureCall(clonedTrail::end);
return "emptyString";
}
我试图Advice
拦截呼叫,但搞砸了对象引用。我一直在研究 byte-buddy 测试用例以及阅读 ASM,但到目前为止还没有取得很大进展。
解决方案
这可以通过覆盖参数的建议来完成。
@Advice.OnMethodEnter
static void enter(@Advice.Argument(readOnly = false) Trail trail) {
trail = trail.clone("test");
}
推荐阅读
- python - Assign group to consecutive 1s in a Pandas Column
- flutter - How to open flutter plugins at Xcode?
- colors - 反转材质内部的颜色(UE4)?
- java - 我应该传递参数还是将它们注入到需要它们的地方?
- c++ - 试图创建类对象的基于堆栈的缓冲区溢出
- ruby-on-rails - Can two customers use same source on Stripe
- excel - 使用 NPIO 制作 Excel 然后用 FileStreamResult 发回?
- sql - 将二进制十六进制表示转换为保持相同输出的字符串
- python - Pyhon - 带有pynput的“侦听器回调中未处理的异常”
- javascript - Why is my variable returning undefined in javascript?