ByteBuddy 代理 class 在什么情况下无法访问自己定义的私有字段?

Under what circumstances will a ByteBuddy proxy class be unable to access its own defined private fields?

我正在尝试理解这个难以理解的错误消息:

java.lang.IllegalStateException: Cannot access private final com.foo.TestMethodInvoker$Foo com.bar.$MyProxy.methodHousing from class com.bar.$MyProxy
at net.bytebuddy.implementation.MethodCall$TargetHandler$ForField$Location$ForExplicitField.resolve(MethodCall.java:2406)
    at net.bytebuddy.implementation.MethodCall$TargetHandler$ForField$Factory.make(MethodCall.java:2444)
    at net.bytebuddy.implementation.MethodCall$Appender.<init>(MethodCall.java:3500)
    at net.bytebuddy.implementation.MethodCall.appender(MethodCall.java:676)
    at net.bytebuddy.dynamic.scaffold.MethodRegistry$Handler$ForImplementation.compile(MethodRegistry.java:233)
    at net.bytebuddy.dynamic.scaffold.MethodRegistry$Handler$ForImplementation.compile(MethodRegistry.java:205)
    at net.bytebuddy.dynamic.scaffold.MethodRegistry$Default$Prepared.compile(MethodRegistry.java:740)
    at net.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:218)
    at net.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:204)
    at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:3595)
    at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase$Delegator.make(DynamicType.java:3819)

我有一个单元测试 (TestMethodInvoker),它定义了一个名为 Foo.

public static 嵌套 class

我的 ByteBuddy 配方定义了一个名为 methodHousingprivate final com.foo.TestMethodInvoker$Foo 字段。

我使用 FieldAccessor.of 对这个字段做各种事情。 (或者我正在尝试!)

错误消息似乎告诉我我的代理 class 无法访问它自己的私有字段 (!)。

在什么情况下会出现这种情况?或者我做错了什么?

您 运行 遇到了 I just fixed on the master branch 的错误。这将在字节好友 1.10.14 中发布。

如果您想同时避免此错误,请避免将显式字段引用作为参数,但提供解析该字段的匹配器。