无法使用Bytebuddy添加会员企业

发布于 2025-01-25 03:26:48 字数 816 浏览 4 评论 0原文

我正在尝试添加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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扮仙女 2025-02-01 03:26:48

尝试成员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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文