无法使用Bytebuddy添加会员企业
我正在尝试添加insurubstitution
使用字节buddy拦截对特定字段的任何访问权限,但是在运行以下代码时,我会收到此错误:无法解析com.test.myclass $ bytebuddybuddy $ pdqdmf1w使用net.bytebuddy.pool.typoolqulqulqulloading@5e712ea6
final var bytebuddy = new ByteBuddy();
var instrumentedType =
bytebuddy
.subclass(MyClass.class)
.method(ElementMatchers.any())
.intercept(MethodDelegation.to(MethodInterceptor.class))
.visit(MemberSubstitution.strict()
.field(ElementMatchers.named("fieldName"))
.onRead()
.stub()
.on(ElementMatchers.any()))
.make()
.load(MyClass.class.getClassLoader())
.getLoaded();
如果我将调用删除到访问
方法,则一切都按预期工作(每个方法调用都会截获)。
相反,如果我只保留访问
方法的呼叫,我也不例外,但是替代似乎不起作用。
I'm trying to add a MemberSubstitution
using ByteBuddy to intercept any access to a specific field, but when running the following code I get this error: Could not resolve com.test.MyClass$ByteBuddy$PdQdmF1w using net.bytebuddy.pool.TypePool$ClassLoading@5e712ea6
final var bytebuddy = new ByteBuddy();
var instrumentedType =
bytebuddy
.subclass(MyClass.class)
.method(ElementMatchers.any())
.intercept(MethodDelegation.to(MethodInterceptor.class))
.visit(MemberSubstitution.strict()
.field(ElementMatchers.named("fieldName"))
.onRead()
.stub()
.on(ElementMatchers.any()))
.make()
.load(MyClass.class.getClassLoader())
.getLoaded();
If I remove the call to the visit
method, everything works as expected (every method call gets intercepted).
On the contrary, if I retain only the call to the visit
method, I get no exception, but the substitution does not seem to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
成员ubstitution.relaxed()
。有一个没有明显字节代码的生成类型,替代方案努力解决。因此,放松的分辨率可以简单地跳过这些类型。Try
MemberSubstitution.relaxed()
. There is a generated type without manifest byte code that the substitution struggles to resolve. Therefore, the relaxed resolution can simply skip those types.