spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.25k stars 40.7k forks source link

Mockito init error with jdk 21 and spring 3.2.1 #38925

Closed zhangjunapk closed 10 months ago

zhangjunapk commented 10 months ago

i had a problem when i using jdk 21 and spring 3.2.1,

dependency tree

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ cross ---
[INFO] org.zj:cross:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.2.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:3.2.1:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:3.2.1:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:3.2.1:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:3.2.1:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.4.14:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.4.14:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.21.1:compile
[INFO] |  |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.21.1:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:2.0.9:compile
[INFO] |  |  +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:2.2:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:3.2.1:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.15.3:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.15.3:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.15.3:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:3.2.1:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:10.1.17:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:10.1.17:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:10.1.17:compile
[INFO] |  +- org.springframework:spring-web:jar:6.1.2:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:6.1.2:compile
[INFO] |  |  \- io.micrometer:micrometer-observation:jar:1.12.1:compile
[INFO] |  |     \- io.micrometer:micrometer-commons:jar:1.12.1:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:6.1.2:compile
[INFO] |     +- org.springframework:spring-aop:jar:6.1.2:compile
[INFO] |     +- org.springframework:spring-context:jar:6.1.2:compile
[INFO] |     \- org.springframework:spring-expression:jar:6.1.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:3.2.1:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:3.2.1:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:3.2.1:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.8.0:test
[INFO] |  +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.1:test
[INFO] |  |  \- jakarta.activation:jakarta.activation-api:jar:2.1.2:test
[INFO] |  +- net.minidev:json-smart:jar:2.5.0:test
[INFO] |  |  \- net.minidev:accessors-smart:jar:2.5.0:test
[INFO] |  |     \- org.ow2.asm:asm:jar:9.3:test
[INFO] |  +- org.assertj:assertj-core:jar:3.24.2:test
[INFO] |  |  \- net.bytebuddy:byte-buddy:jar:1.12.21:test
[INFO] |  +- org.awaitility:awaitility:jar:4.2.0:test
[INFO] |  +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] |  +- org.junit.jupiter:junit-jupiter:jar:5.10.1:test
[INFO] |  |  +- org.junit.jupiter:junit-jupiter-api:jar:5.10.1:test
[INFO] |  |  |  +- org.opentest4j:opentest4j:jar:1.3.0:test
[INFO] |  |  |  +- org.junit.platform:junit-platform-commons:jar:1.10.1:test
[INFO] |  |  |  \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] |  |  +- org.junit.jupiter:junit-jupiter-params:jar:5.10.1:test
[INFO] |  |  \- org.junit.jupiter:junit-jupiter-engine:jar:5.10.1:test
[INFO] |  |     \- org.junit.platform:junit-platform-engine:jar:1.10.1:test
[INFO] |  +- org.mockito:mockito-core:jar:5.7.0:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.14.9:test
[INFO] |  |  \- org.objenesis:objenesis:jar:3.3:test
[INFO] |  +- org.mockito:mockito-junit-jupiter:jar:5.7.0:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.1:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:6.1.2:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:6.1.2:compile
[INFO] |  +- org.springframework:spring-test:jar:6.1.2:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.9.1:test
[INFO] +- org.springframework.boot:spring-boot-starter-graphql:jar:3.2.1:compile
[INFO] |  \- org.springframework.graphql:spring-graphql:jar:1.2.4:compile
[INFO] |     +- com.graphql-java:graphql-java:jar:20.7:compile
[INFO] |     |  +- com.graphql-java:java-dataloader:jar:3.2.0:compile
[INFO] |     |  \- org.reactivestreams:reactive-streams:jar:1.0.3:compile
[INFO] |     +- io.projectreactor:reactor-core:jar:3.5.12:compile
[INFO] |     \- io.micrometer:context-propagation:jar:1.0.6:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-webflux:jar:3.2.1:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:3.2.1:compile
[INFO] |  |  \- io.projectreactor.netty:reactor-netty-http:jar:1.1.14:compile
[INFO] |  |     +- io.netty:netty-codec-http:jar:4.1.101.Final:compile
[INFO] |  |     |  +- io.netty:netty-common:jar:4.1.101.Final:compile
[INFO] |  |     |  +- io.netty:netty-buffer:jar:4.1.101.Final:compile
[INFO] |  |     |  +- io.netty:netty-transport:jar:4.1.101.Final:compile
[INFO] |  |     |  +- io.netty:netty-codec:jar:4.1.101.Final:compile
[INFO] |  |     |  \- io.netty:netty-handler:jar:4.1.101.Final:compile
[INFO] |  |     +- io.netty:netty-codec-http2:jar:4.1.101.Final:compile
[INFO] |  |     +- io.netty:netty-resolver-dns:jar:4.1.101.Final:compile
[INFO] |  |     |  +- io.netty:netty-resolver:jar:4.1.101.Final:compile
[INFO] |  |     |  \- io.netty:netty-codec-dns:jar:4.1.101.Final:compile
[INFO] |  |     +- io.netty:netty-resolver-dns-native-macos:jar:osx-x86_64:4.1.101.Final:compile
[INFO] |  |     |  \- io.netty:netty-resolver-dns-classes-macos:jar:4.1.101.Final:compile
[INFO] |  |     +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.101.Final:compile
[INFO] |  |     |  +- io.netty:netty-transport-native-unix-common:jar:4.1.101.Final:compile
[INFO] |  |     |  \- io.netty:netty-transport-classes-epoll:jar:4.1.101.Final:compile
[INFO] |  |     \- io.projectreactor.netty:reactor-netty-core:jar:1.1.14:compile
[INFO] |  |        \- io.netty:netty-handler-proxy:jar:4.1.101.Final:compile
[INFO] |  |           \- io.netty:netty-codec-socks:jar:4.1.101.Final:compile
[INFO] |  \- org.springframework:spring-webflux:jar:6.1.2:compile
[INFO] +- org.slf4j:slf4j-api:jar:2.0.9:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.15.3:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.15.3:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-core:jar:2.15.3:compile
[INFO] \- org.projectlombok:lombok:jar:1.18.30:provided

error stack

java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
    at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:84)
    at jdk.proxy2/jdk.proxy2.$Proxy66.getHandler(Unknown Source)
    at org.mockito.internal.util.MockUtil.getMockHandlerOrNull(MockUtil.java:158)
    at org.mockito.internal.util.MockUtil.isMock(MockUtil.java:147)
    at org.mockito.internal.util.DefaultMockingDetails.isMock(DefaultMockingDetails.java:32)
    at org.springframework.boot.test.mock.mockito.MockReset.get(MockReset.java:106)
    at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:85)
    at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:73)
    at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.beforeTestMethod(ResetMocksTestExecutionListener.java:60)
    at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:320)
    at org.springframework.test.context.junit.jupiter.SpringExtension.beforeEach(SpringExtension.java:240)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    Suppressed: java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
        at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:84)
        at jdk.proxy2/jdk.proxy2.$Proxy66.getHandler(Unknown Source)
        at org.mockito.internal.util.MockUtil.getMockHandlerOrNull(MockUtil.java:158)
        at org.mockito.internal.util.MockUtil.isMock(MockUtil.java:147)
        at org.mockito.internal.util.DefaultMockingDetails.isMock(DefaultMockingDetails.java:32)
        at org.springframework.boot.test.mock.mockito.MockReset.get(MockReset.java:106)
        at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:85)
        at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:73)
        at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.afterTestMethod(ResetMocksTestExecutionListener.java:67)
        at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:487)
        at org.springframework.test.context.junit.jupiter.SpringExtension.afterEach(SpringExtension.java:278)
        ... 2 more
    Caused by: java.lang.IllegalStateException: Internal problem occurred, please report it. Mockito is unable to load the default implementation of class that is a part of Mockito distribution. Failed to load interface org.mockito.plugins.MockMaker
        at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.create(DefaultMockitoPlugins.java:105)
        at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.getDefaultPlugin(DefaultMockitoPlugins.java:79)
        at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:75)
        at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:50)
        at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:27)
        at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:22)
        at org.mockito.internal.MockitoCore.<clinit>(MockitoCore.java:73)
        at org.mockito.Mockito.<clinit>(Mockito.java:1683)
        at org.springframework.boot.test.mock.mockito.MockReset.get(MockReset.java:105)
        at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:85)
        at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:73)
        at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.beforeTestMethod(ResetMocksTestExecutionListener.java:60)
        at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:320)
        at org.springframework.test.context.junit.jupiter.SpringExtension.beforeEach(SpringExtension.java:240)
        ... 2 more
    Caused by: java.lang.reflect.InvocationTargetException
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
        at org.mockito.internal.configuration.plugins.DefaultMockitoPlugins.create(DefaultMockitoPlugins.java:103)
        ... 15 more
    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               : 21
JVM vendor name    : Oracle Corporation
JVM vendor version : 21.0.1+12-29
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 21.0.1+12-29
JVM info           : mixed mode, sharing
OS name            : Linux
OS version         : 6.2.0-39-generic

        at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.<init>(InlineDelegateByteBuddyMockMaker.java:260)
        at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:23)
        ... 18 more
    Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@a6e4897
        at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:643)
        at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:616)
        at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:568)
        at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:545)
        at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.<clinit>(InlineDelegateByteBuddyMockMaker.java:133)
        ... 19 more
    Caused by: java.lang.reflect.InvocationTargetException
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at net.bytebuddy.agent.Attacher.install(Attacher.java:102)
        at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:638)
        ... 23 more
    Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file /proc/38800/root/tmp/.java_pid38800: target process 38800 doesn't respond within 10500ms or HotSpot VM not loaded
        at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:99)
        at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
        at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
        ... 26 more
Caused by: [CIRCULAR REFERENCE: java.lang.IllegalStateException: Internal problem occurred, please report it. Mockito is unable to load the default implementation of class that is a part of Mockito distribution. Failed to load interface org.mockito.plugins.MockMaker]
zhangjunapk commented 10 months ago

cant debug my test method

@SpringBootTest
class ApplicationTests {

  @Autowired
  private GraphService graphService;

  @Test
  public void test() {
    graphService.process();
  }
  }
wilkinsona commented 10 months ago

The internal error is occurring in Mockito and should be reported to them as I believe it's out of Spring Boot's control. If you have already investigated and discovered that the problem only occurs when using Spring Boot, please let us know and we can re-open this issue and take another look.