Mockito object is not an instance of declaring class

Had the same issue with my project and used the Rincl project above to confirm I was having the same issue. Using JDK 1.8.0_11 on Mac the reported errors were the same as Garret. Updating to version JDK 1.8.0_181 I ran the Rincl test with NO errors. Apparently Mockito is using the latest of the JDK 1.8.0.


If this is helpful to anyone, I got the same above issue and tried all other options like upgrading the JVM etc, but what solved my issue is : https://github.com/mockito/mockito/issues/1606

By and large reverting my mockito version to 2.23.+ solved the issue for me.


Your Java runtime version is from March 2014; plenty of bugs have been fixed in the VM ever since and you should really upgrade. I am 99% sure that this problem is related to type annotations (@NonNull) which were introduced in this version for the first time in this exact release. I am sure that your problem will go away if you upgrade your VM.

I can successfully execute your proposed test with a recent build of the HotSpot VM.

Tags:

Java

Mockito