Issue
I have a bunch of Spring Boot 2.5.6 applications that use Mockito for unit testing. The version of Mockito that is used is the one that comes shipped within SB itself (3.9.0). The JDK is OpenJDK 11.0.12+0. Everything was working fine up until yesterday, this morning I suddenly cannot run any Mockito-based tests, all of them fail with the following:
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.CompoundEnumeration@7c51f34b
Caused by: java.lang.reflect.InvocationTargetException
Caused by: org.mockito.exceptions.base.MockitoInitializationException:
Could not initialize inline Byte Buddy mock maker.
It appears as if your JDK does not supply a working agent attachment mechanism.
Java : 11
JVM vendor name : Homebrew
JVM vendor version : 11.0.12+0
JVM name : OpenJDK 64-Bit Server VM
JVM version : 11.0.12+0
JVM info : mixed mode
OS name : Mac OS X
OS version : 12.0.1
Caused by: java.lang.IllegalStateException: Could not self-attach to current VM using external process
I cannot identify anything that has changed between yesterday and today.
Things I have tried with no success:
- Re-run with Java 17.
- Re-install Java 11.
- Install a JDK 11 from a different vendor (Microsoft OpenJDK)
- Add
-Djdk.attach.allowAttachSelf=true
, both to command line and to<argLine>
parameter within surefire configuration, as suggested here - Add
-XX:+StartAttachListener
as suggested here - Restart the computer
- Ensure the firewall allows the
java
process to receive incoming connections as per here - (Temporarily) stop any security software that may prevent connections from happening
- Review
JAVA_HOME
and the different Java installations on my machine in case the process was trying to attach to the wrong Java as per here
In case it matters, this is on a MBP M1. Other members of the team are able to build with no problem.
Solution
Not sure how much of an answer this will be, but the issue is now (seemingly) self-fixed... I'll describe what I've done and what happened in case it helps other users experiencing similar issues.
After unsuccessfully trying all the things described in the question, I had to restart the laptop (again) for an unrelated problem (Zoom wouldn't start up). Upon restart the laptop simply crashed and restarted again on its own. Then it did the same a second time. Upon the third automatic restart, I was no longer experiencing issues building my Java applications.
My guess is that the NVRAM got somehow corrupted and this was affecting the JVM's ability to accept incoming requests for attachment. On a MBP M1 one cannot reset the NVRAM as with Intel models (pressing Cmd + Opt + R + P), instead the NVRAM is supposed to self-heal when it detects something wrong. I suppose after crashing the MBP finally decided to repair the NVRAM and that's why the build starting working again.
UPDATE: I have now encountered this issue a few more times and every time the "solution" was to restart the laptop a few times until it crashed. After that the issue would disappear. This adds weight to the idea that there is some inherent instability with the combination of hardware and software specified in the question. I'll leave this as an "answered" question in case anybody else has the same issue.
UPDATE 2: This may be pure coincidence, but the issue seems to be exacerbated by the usage of an additional screen, particularly using an iPad via Sidecar.
Answered By - quiram
Answer Checked By - Marie Seifert (JavaFixing Admin)