You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mockito running under java 17 with default settings seems to produce incorrect mocks. What's worse: Mockito produces incorrect mocks silently. The problem can be fixed by invoking java with --add-opens jvm options, but I would expect mockito to fail and in the best case show meaningful text describing the nature of the problem and a possible fix.
Code run with java11: works
Code run with java 17: fails with NPE (consequence of broken mock)
Code run with java 17 --add-opens=java.base/java.io=ALL-UNNAMED: works
Environment
Mockito: 4.3.1
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-Debian-1)
OpenJDK 64-Bit Server VM (build 17.0.1+12-Debian-1, mixed mode, sharing)
Expectations
mockito should either
produce correct mocks
OR
fail with Exception if correct mocks cannot be produced with the current jvm settings
Unfortunately, ObjectOutputStream is one of the classes that Mockito relies on internally for its behavior. Stubbing ObjectOutputStream will therefore lead to undefined behavior. Additionally, it is advised not to mock classes you don't own: https://github.com/mockito/mockito/wiki/How-to-write-good-tests#dont-mock-a-type-you-dont-own We are working on improving the user experience by working on a DoNotMock feature to avoid mocking classes/methods that are known to crash Mockito internals (#1833). Therefore, I am closing this as "Infeasible". Apologies for the uninformative exception that is thrown.
mockito running under java 17 with default settings seems to produce incorrect mocks. What's worse: Mockito produces incorrect mocks silently. The problem can be fixed by invoking java with
--add-opens
jvm options, but I would expect mockito to fail and in the best case show meaningful text describing the nature of the problem and a possible fix.--add-opens=java.base/java.io=ALL-UNNAMED
: worksEnvironment
Expectations
mockito should either
OR
Code
(complete example here: https://github.com/montanero/mockito-bug.git)
The text was updated successfully, but these errors were encountered: