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
Spies don't behave properly when running in Java 17 #2573
Comments
I'm not sure how I was so far behind in Mockito versions. I've verified this with Mockito 4.3.1 as well - same behavior with Java 17.0.2. |
Does this issue reproduce with |
@TimvdLippe - Looks like Tanks for the tip! |
Yes, we are currently discussing switching to |
When ever you encounter this Spy related issue with Java 17, where Spy object is null then we need to pass vm argurment for that kind of package like --add-opens=java.desktop/sun.java2d=ALL-UNNAMED |
The following code works with Mockito 3.11.2 and JDK 8, 11 and 14, but not JDK 16 or 17 (couldn't verify 15, sorry). I'm not sure if this is a bytecode change causing trouble or something else.
Environment info:
Example JUnit test showing the difference in behavior:
Expected behavior:
The test passes (seen with JDK <= 14).
Actual behavior:
The test fails when running under JDK 16 or 17 with the error below. It appears as though the spy has fields that are
null
that are notnull
in the spied-on instance (verified by inspecting in a debugger):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: