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
It works in Java 17, but it doesn't work in Java 21. I got this error messages:
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class java.nio.ByteBuffer.
If you're not sure why you're getting this error, please open an issue on GitHub.
Java : 21
JVM vendor name : Red Hat, Inc.
JVM vendor version : 21.0.1+12-LTS
JVM name : OpenJDK 64-Bit Server VM
JVM version : 21.0.1+12-LTS
JVM info : mixed mode, sharing
OS name : Windows 10
OS version : 10.0
You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.
Underlying exception : org.mockito.exceptions.base.MockitoException: Unsupported settings with this type 'java.nio.ByteBuffer'
at org.mockito.junit.jupiter.MockitoExtension.beforeEach(MockitoExtension.java:159)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Suppressed: java.lang.NullPointerException: Cannot invoke "java.util.Set.forEach(java.util.function.Consumer)" because the return value of "org.junit.jupiter.api.extension.ExtensionContext$Store.remove(Object, java.lang.Class)" is null
at org.mockito.junit.jupiter.MockitoExtension.afterEach(MockitoExtension.java:190)
... 2 more
Caused by: org.mockito.exceptions.base.MockitoException: Unsupported settings with this type 'java.nio.ByteBuffer'
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:168)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:399)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:190)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:410)
... 3 more
Unfortunately, ByteBuffer is one of the classes that Mockito relies on internally for its behavior. Stubbing ByteBuffer 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.
It works in Java 17, but it doesn't work in Java 21. I got this error messages:
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class java.nio.ByteBuffer.
If you're not sure why you're getting this error, please open an issue on GitHub.
Java : 21
JVM vendor name : Red Hat, Inc.
JVM vendor version : 21.0.1+12-LTS
JVM name : OpenJDK 64-Bit Server VM
JVM version : 21.0.1+12-LTS
JVM info : mixed mode, sharing
OS name : Windows 10
OS version : 10.0
You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.
Underlying exception : org.mockito.exceptions.base.MockitoException: Unsupported settings with this type 'java.nio.ByteBuffer'
the code:
The text was updated successfully, but these errors were encountered: