-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Exception "The mock object was garbage collected." #1802
Comments
I tried bisecting. This issue happens after this PR. |
That makes sence, if the Thanks for the test, since we both have a test for the "too weak" and the "not sufficiently weak" mock applications, I hope that I can come up with a scenario that satisfies both conditions. |
This issue just came up as we tried to upgrade from 3.3.3 to either 3.4.6 or 3.5.9. A large chunk of our unit tests became flaky as a result. Holding onto a strong reference of Considering that |
Yes, this needs to be addressed. The alternatives right now are unfortunately a leak or premature discarding. I think a leak is the better alternative, though since you can explicitly clear Mockito's mock store. The updates within 3 should not have an impact but can have one as a result of changed GC cycles. I will try to solve this one the next time I find some free time to work on Mockito. |
Awesome! Thanks so much for addressing this! |
We received the following exception while running tests using Mockito, either version 3.0.0 or 3.1.0, and I'm filing this bug as requested:
I've reduced the problem to the following test program:
Whether the problem occurs depends on what exactly the JVM does with the code. It looks like the mock object can be garbage collected between the call to the mocked method and Mockito trying to use the weak reference to it. I'm using AdoptOpenJDK 11.0.3.7-hotspot on Windows. My test program more often than not reproduces the exception within a few seconds, but occasionally it can run forever without failing.
The text was updated successfully, but these errors were encountered: