New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spy does not initialize objects fully with InstrumentationMemberAccessor #2947
Comments
Ah, after a bit of head scratching I figured it out. We have a snippet of code that selects the super constructor to call from a constructor that is
That visibility check is no longer correct with nestmates (Java 11+) where javac does no longer create bridge methods to give access to private constructors, but where the access right is registered as an attribute. isPrivate needed to be replaced with isAccessible where the access right is evaluated with respect to all available properties by Byte Buddy. |
Fixed in #2948 |
Thank you, that was quick! |
I see the merge to master, is there a 4.x version where I can get this fix ? |
Unfortunately no, we don't have capacity to backport changes. |
I still need this to work on both Java 8 & 17 and so can't switch to 5.x. I guess the only option is to switch private access to default in the outer class until we can switch to 5.x. |
If you make the constructor package-private, that's basically what javac did for you on 8. |
With mockito-inline, spy objects are missing fields when spying on child classes whose base class constructor is private. The issue goes away when base class constructor is made default access or public.
This prints
p2 is non-null in original object but becomes null in the spy. This issue does not happen in mockito-core with ReflectionMemberAccessor. If the constructor of C is made default or public, the issue does not occur.
Versions:
Mockito-Inline : 4.10
JDK - 17
check that
Note that some configuration are impossible to mock via Mockito
(same as any question on stackoverflow.com)
The text was updated successfully, but these errors were encountered: