question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IndyBootstrap classloading problem

See original GitHub issue

As reported in forum. Problem with 1.18.1(and current master branch) versions. Application on spring boot version 2.3.4, tomcat version - 9.0.37-jdk11-openjdk.

2020-10-21 14:48:58,919 [main] TRACE co.elastic.apm.agent.bci.ElasticApmAgent - Advice co.elastic.apm.agent.bootdelegation.BootstrapDelegationClassLoaderInstrumentation is loaded by null
2020-10-21 14:48:58,920 [main] TRACE co.elastic.apm.agent.bci.ElasticApmAgent - java.net.URLClassLoader@72cf2de5 can load advice (co.elastic.apm.agent.bootdelegation.BootstrapDelegationClassLoaderInstrumentation): true
2020-10-21 14:48:58,920 [main] TRACE co.elastic.apm.agent.bci.ElasticApmAgent - Advice co.elastic.apm.agent.bootdelegation.BootstrapDelegationClassLoaderInstrumentation is loaded by null
2020-10-21 14:48:58,920 [main] TRACE co.elastic.apm.agent.bci.ElasticApmAgent - jdk.internal.loader.ClassLoaders$AppClassLoader@3d4eac69 can load advice (co.elastic.apm.agent.bootdelegation.BootstrapDelegationClassLoaderInstrumentation): true
2020-10-21 14:48:58,920 [main] TRACE co.elastic.apm.agent.bci.ElasticApmAgent - Advice co.elastic.apm.agent.bootdelegation.BootstrapDelegationClassLoaderInstrumentation is loaded by null
2020-10-21 14:48:58,920 [main] TRACE co.elastic.apm.agent.bci.ElasticApmAgent - jdk.internal.loader.ClassLoaders$PlatformClassLoader@16612a51 can load advice (co.elastic.apm.agent.bootdelegation.BootstrapDelegationClassLoaderInstrumentation): true
2020-10-21 14:48:58,920 [main] TRACE co.elastic.apm.agent.bci.ElasticApmAgent - Advice co.elastic.apm.agent.bootdelegation.BootstrapDelegationClassLoaderInstrumentation is loaded by null
2020-10-21 14:48:58,920 [main] TRACE co.elastic.apm.agent.bci.ElasticApmAgent - bootstrap classloader
2020-10-21 14:48:59,227 [main] DEBUG co.elastic.apm.agent.bci.IndyPluginClassLoaderFactory - Creating plugin class loader for ParallelWebappClassLoader
  context: demo1
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@72cf2de5
 containing [co.elastic.apm.agent.springwebmvc.ExceptionHandlerInstrumentation, co.elastic.apm.agent.springwebmvc.package-info, co.elastic.apm.agent.springwebmvc.ExceptionHandlerInstrumentation$ExceptionHandlerAdviceService, co.elastic.apm.agent.springwebmvc.ViewRenderInstrumentation$ViewRenderAdviceService, co.elastic.apm.agent.springwebmvc.SpringTransactionNameInstrumentation, co.elastic.apm.agent.springwebmvc.SpringTransactionNameInstrumentation$HandlerAdapterAdvice, co.elastic.apm.agent.springwebmvc.SpringServiceNameInstrumentation$SpringServiceNameAdvice, co.elastic.apm.agent.springwebmvc.SpringServiceNameInstrumentation, co.elastic.apm.agent.springwebmvc.ViewRenderInstrumentation]
2020-10-21 14:48:59,236 [main] ERROR co.elastic.apm.agent.bci.IndyBootstrap - no such method: co.elastic.apm.agent.springwebmvc.SpringServiceNameInstrumentation$SpringServiceNameAdvice.afterInitPropertySources(WebApplicationContext)void/invokeStatic
java.lang.IllegalAccessException: no such method: co.elastic.apm.agent.springwebmvc.SpringServiceNameInstrumentation$SpringServiceNameAdvice.afterInitPropertySources(WebApplicationContext)void/invokeStatic
	at java.lang.invoke.MemberName.makeAccessException(MemberName.java:959) ~[?:?]
	at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1101) ~[?:?]
	at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:2030) ~[?:?]
	at java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:1102) ~[?:?]
	at co.elastic.apm.agent.bci.IndyBootstrap.bootstrap(IndyBootstrap.java:290) [?:?]
	at jdk.internal.reflect.GeneratedMethodAccessor24.invoke(Unknown Source) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at java.lang.IndyBootstrapDispatcher.bootstrap(IndyBootstrapDispatcher.java:31) [?:?]
	at java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:138) [?:?]
	at java.lang.invoke.CallSite.makeSite(CallSite.java:307) [?:?]
	at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:258) [?:?]
	at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:248) [?:?]
	at org.springframework.web.context.support.GenericWebApplicationContext.initPropertySources(GenericWebApplicationContext.java:196) [spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:601) [spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.prepareRefresh(AnnotationConfigServletWebServerApplicationContext.java:195) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520) [spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
	at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:173) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
	at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:153) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
	at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:95) [spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
	at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172) [spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5139) [catalina.jar:9.0.20]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:9.0.20]
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:713) [catalina.jar:9.0.20]
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690) [catalina.jar:9.0.20]
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705) [catalina.jar:9.0.20]
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:978) [catalina.jar:9.0.20]
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1849) [catalina.jar:9.0.20]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-util.jar:9.0.20]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118) [?:?]
	at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:773) [catalina.jar:9.0.20]
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427) [catalina.jar:9.0.20]
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1576) [catalina.jar:9.0.20]
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309) [catalina.jar:9.0.20]
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123) [catalina.jar:9.0.20]
	at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423) [catalina.jar:9.0.20]
	at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366) [catalina.jar:9.0.20]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:929) [catalina.jar:9.0.20]
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841) [catalina.jar:9.0.20]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:9.0.20]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377) [catalina.jar:9.0.20]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367) [catalina.jar:9.0.20]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) [tomcat-util.jar:9.0.20]
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140) [?:?]
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902) [catalina.jar:9.0.20]
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [catalina.jar:9.0.20]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:9.0.20]
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) [catalina.jar:9.0.20]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:9.0.20]
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932) [catalina.jar:9.0.20]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:9.0.20]
	at org.apache.catalina.startup.Catalina.start(Catalina.java:633) [catalina.jar:9.0.20]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:344) [bootstrap.jar:9.0.20]
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475) [bootstrap.jar:9.0.20]
Caused by: java.lang.LinkageError: bad method type alias: (WebApplicationContext)void not visible from class co.elastic.apm.agent.springwebmvc.SpringServiceNameInstrumentation$SpringServiceNameAdvice
	at java.lang.invoke.MemberName.checkForTypeAlias(MemberName.java:872) ~[?:?]
	at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:1074) ~[?:?]
	at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1098) ~[?:?]
	... 64 more
2020-10-21 14:48:59,538 [Thread-16] DEBUG co.elastic.apm.agent.bci.ElasticApmAgent - Type match for instrumentation ServletInstrumentation: ((not(isInterface()) and hasSuperType(erasure(name(equals(javax.servlet.Servlet))))) and not(isInterface())) matches class org.springframework.web.servlet.DispatcherServlet
2020-10-21 14:48:59,538 [Thread-16] TRACE co.elastic.apm.agent.bci.ElasticApmAgent - Advice co.elastic.apm.agent.servlet.ServletInstrumentation is loaded by null
2020-10-21 14:48:59,539 [Thread-16] TRACE co.elastic.apm.agent.bci.ElasticApmAgent - ParallelWebappClassLoader
  context: demo1
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@72cf2de5
 can load advice (co.elastic.apm.agent.servlet.ServletInstrumentation): true

...
2020-10-21 14:49:02,381 [main] DEBUG co.elastic.apm.agent.bci.IndyPluginClassLoaderFactory - Creating plugin class loader for ParallelWebappClassLoader
  context: demo1
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@72cf2de5
 containing [co.elastic.apm.agent.micrometer.MicrometerMetricsReporter, co.elastic.apm.agent.micrometer.MicrometerInstrumentation, co.elastic.apm.agent.micrometer.MicrometerMeterRegistrySerializer, co.elastic.apm.agent.micrometer.MicrometerMetricsReporter$MeterMapConsumer]
2020-10-21 14:49:02,386 [main] ERROR co.elastic.apm.agent.bci.IndyBootstrap - no such method: co.elastic.apm.agent.micrometer.MicrometerInstrumentation.onExit(MeterRegistry)void/invokeStatic
java.lang.IllegalAccessException: no such method: co.elastic.apm.agent.micrometer.MicrometerInstrumentation.onExit(MeterRegistry)void/invokeStatic
	at java.lang.invoke.MemberName.makeAccessException(MemberName.java:959) ~[?:?]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
felixbarnycommented, Nov 12, 2020

I have found the moment after which calling Class.forName("org.springframework.web.context.WebApplicationContext", false, indyPluginClassLoader) yields a LinkageError. It happens after calling the native method MethodHandleNatives.resolve(m, lookupClass, speculativeResolve)

	at java.base/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:1070)
	at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1098)
	at java.base/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:2030)
	at java.base/java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:1102)
	at co.elastic.apm.agent.bci.IndyBootstrap.bootstrap(IndyBootstrap.java:289)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.lang.IndyBootstrapDispatcher.bootstrap(IndyBootstrapDispatcher.java:31)
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:138)
	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:307)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:258)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:248)
	at org.springframework.web.context.support.GenericWebApplicationContext.initPropertySources(GenericWebApplicationContext.java:196)
	[...]

Calling Class.forName("org.springframework.web.context.WebApplicationContext", false, indyPluginClassLoader) before this point correctly loads the class. However, when doing so, MethodHandleNatives.resolve fails with the following exception:

java.lang.LinkageError: loader constraint violation: when resolving method 'void co.elastic.apm.agent.springwebmvc.SpringServiceNameInstrumentation$SpringServiceNameAdvice.afterInitPropertySources(org.springframework.web.context.WebApplicationContext)' the class loader 'bootstrap' of the current class, co/elastic/apm/agent/bci/IndyBootstrap, and the class loader co.elastic.apm.agent.bci.classloading.IndyPluginClassLoader @249d9385 for the method's defining class, co/elastic/apm/agent/springwebmvc/SpringServiceNameInstrumentation$SpringServiceNameAdvice, have different Class objects for the type org/springframework/web/context/WebApplicationContext used in the signature (co.elastic.apm.agent.bci.IndyBootstrap is in unnamed module of loader 'bootstrap'; co.elastic.apm.agent.springwebmvc.SpringServiceNameInstrumentation$SpringServiceNameAdvice is in unnamed module of loader co.elastic.apm.agent.bci.classloading.IndyPluginClassLoader @249d9385, parent loader co.elastic.apm.agent.shaded.bytebuddy.dynamic.loading.MultipleParentClassLoader @5d3b5781)

	at java.base/java.lang.invoke.MethodHandleNatives.resolve(Native Method)
	at java.base/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:1070)
	at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1098)
	at java.base/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:2030)
	at java.base/java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:1102)
	at co.elastic.apm.agent.bci.IndyBootstrap.bootstrap(IndyBootstrap.java:289)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.lang.IndyBootstrapDispatcher.bootstrap(IndyBootstrapDispatcher.java:31)
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:138)
	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:307)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:258)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:248)
	at org.springframework.web.context.support.GenericWebApplicationContext.initPropertySources(GenericWebApplicationContext.java:196)

What doesn’t make sense is that the bootstrap class loader does not define org/springframework/web/context/WebApplicationContext. The issue seems to be that the lookup is made via MethodHandles.lookup(), using the current class as the lookup class. In this case, the lookup class is IndyBootstrap, which is loaded by the bootstrap classloader (added via Instrumentation#appendToBootstrapClassLoaderSearch). What probably happens is that the JVM thinks that classes resolved during MethodHandleNatives.resolve(m, lookupClass, speculativeResolve) are loaded by the lookup class’s class loader. When doing another lookup with the same lookup class but in the context of a different web application, it thinks WebApplicationContext has already been defined in the current class loader hierarchy. This is not true as the bootstrap class loader does not define WebApplicationContext.

Solution: I’ve found a fix for it. Instead of using MethodHandles.lookup(), which uses the caller class as the lookup class, using a MethodHandles.Lookup instance from a class that’s declared by the IndyPluginClassLoader helps!

https://github.com/elastic/apm-agent-java/blob/4ef35f746671d3fee75c8b3f3462e7dcc92b0089/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/IndyBootstrap.java#L290

Update: PR ready: #1458

0reactions
felixbarnycommented, Oct 26, 2020

I can reproduce the issue now. It happens when deploying two web applications to the same Tomcat server.

During the indy bootstrap, it tries to load org.springframework.web.context.WebApplicationContext from IndyPluginClassLoader to check if the parameter of the advice method is visible to the advice class.

https://github.com/elastic/apm-agent-java/blob/dd90bc45e78dd0e2f2110a7da3f4fd57f7337ce6/apm-agent-plugins/apm-spring-webmvc-plugin/src/main/java/co/elastic/apm/agent/springwebmvc/SpringServiceNameInstrumentation.java#L70-L73

That check goes fine when deploying the first web application. But when deploying a second web app where SpringServiceNameInstrumentation is applied (such as the same application under a different context path), that check fails with the following message: loader constraint violation: loader co.elastic.apm.agent.bci.classloading.IndyPluginClassLoader @7041ed62 wants to load interface org.springframework.web.context.WebApplicationContext. A different interface with the same name was previously loaded by org.apache.catalina.loader.ParallelWebappClassLoader @4aff898d. (org.springframework.web.context.WebApplicationContext is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @4aff898d, parent loader java.net.URLClassLoader @10027fc9)

java.lang.LinkageError: loader constraint violation: loader co.elastic.apm.agent.bci.classloading.IndyPluginClassLoader @7041ed62 wants to load interface org.springframework.web.context.WebApplicationContext. A different interface with the same name was previously loaded by org.apache.catalina.loader.ParallelWebappClassLoader @4aff898d. (org.springframework.web.context.WebApplicationContext is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @4aff898d, parent loader java.net.URLClassLoader @10027fc9)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:398)
	at java.base/sun.invoke.util.VerifyAccess$1.run(VerifyAccess.java:292)
	at java.base/sun.invoke.util.VerifyAccess$1.run(VerifyAccess.java:289)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/sun.invoke.util.VerifyAccess.isTypeVisible(VerifyAccess.java:288)
	at java.base/sun.invoke.util.VerifyAccess.isTypeVisible(VerifyAccess.java:312)
	at java.base/java.lang.invoke.MemberName.checkForTypeAlias(MemberName.java:871)
	at java.base/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:1074)
	at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1098)
	at java.base/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:2030)
	at java.base/java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:1102)
	at co.elastic.apm.agent.bci.IndyBootstrap.bootstrap(IndyBootstrap.java:289)
	at java.base/jdk.internal.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.lang.IndyBootstrapDispatcher.bootstrap(IndyBootstrapDispatcher.java:31)
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:138)
	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:307)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:258)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:248)
	at org.springframework.web.context.support.GenericWebApplicationContext.initPropertySources(GenericWebApplicationContext.java:196)
	at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:601)
	at org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext.prepareRefresh(AnnotationConfigServletWebServerApplicationContext.java:195)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:173)
	at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:153)
	at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:95)
	at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5055)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:742)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:718)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:703)
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1736)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
	at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
	at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:456)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:405)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
	at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
	at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at java.management/com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1406)
	at java.management.rmi/javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:827)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

Apparently, calling Class.forName("org.springframework.web.context.WebApplicationContext", false, indyPluginClassLoader) fails because org.springframework.web.context.WebApplicationContext is already loaded from a different class loading hierarchy. Interestingly, calling indyPluginClassLoader.loadClass("org.springframework.web.context.WebApplicationContext"), as well as Class.forName("org.springframework.web.context.WebApplicationContext", false, indyPluginClassLoader.parent) succeeds.

When I’ve tested this on Java 11 (“update 0”), the JVM even crashed with a segfault. The report contains this stack trace:

---------------  T H R E A D  ---------------

Current thread (0x00007ff9c9c62000):  JavaThread "RMI TCP Connection(3)-127.0.0.1" daemon [_thread_in_vm, id=55819, stack(0x000070000ea11000,0x000070000eb11000)]

Stack: [0x000070000ea11000,0x000070000eb11000],  sp=0x000070000eb06d10,  free space=983k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.dylib+0x1fe285]  ClassLoaderData::loader_name_and_id() const+0x7
V  [libjvm.dylib+0x3aea70]  java_lang_ClassLoader::describe_external(oopDesc*)+0xe0
V  [libjvm.dylib+0x6d75a9]  SystemDictionary::check_constraints(unsigned int, InstanceKlass*, Handle, bool, Thread*)+0x143
V  [libjvm.dylib+0x6d657e]  SystemDictionary::resolve_instance_class_or_null(Symbol*, Handle, Handle, Thread*)+0x512
V  [libjvm.dylib+0x6d5cd1]  SystemDictionary::resolve_or_fail(Symbol*, Handle, Handle, bool, Thread*)+0x1b
V  [libjvm.dylib+0x41da4b]  find_class_from_class_loader(JNIEnv_*, Symbol*, unsigned char, Handle, Handle, unsigned char, Thread*)+0x30
V  [libjvm.dylib+0x41d977]  JVM_FindClassFromCaller+0x1f9
C  [libjava.dylib+0x1b37]  Java_java_lang_Class_forName0+0x129
J 658  java.lang.Class.forName0(Ljava/lang/String;ZLjava/lang/ClassLoader;Ljava/lang/Class;)Ljava/lang/Class; java.base@11 (0 bytes) @ 0x000000011ef03647 [0x000000011ef03540+0x0000000000000107]
J 5808 c2 java.lang.Class.forName(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class; java.base@11 (47 bytes) @ 0x000000011f057a74 [0x000000011f057a40+0x0000000000000034]
j  sun.invoke.util.VerifyAccess$1.run()Ljava/lang/Class;+9 java.base@11
j  sun.invoke.util.VerifyAccess$1.run()Ljava/lang/Object;+1 java.base@11
v  ~StubRoutines::call_stub
V  [libjvm.dylib+0x3a588a]  JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, Thread*)+0x21a
V  [libjvm.dylib+0x41ff3f]  JVM_DoPrivileged+0x6d2
J 678  java.security.AccessController.doPrivileged(Ljava/security/PrivilegedAction;)Ljava/lang/Object; java.base@11 (0 bytes) @ 0x000000011ef05c12 [0x000000011ef05b40+0x00000000000000d2]
J 394 c1 sun.invoke.util.VerifyAccess.isTypeVisible(Ljava/lang/Class;Ljava/lang/Class;)Z java.base@11 (118 bytes) @ 0x0000000117a19574 [0x0000000117a18120+0x0000000000001454]
J 2846 c1 sun.invoke.util.VerifyAccess.isTypeVisible(Ljava/lang/invoke/MethodType;Ljava/lang/Class;)Z java.base@11 (47 bytes) @ 0x0000000117f12414 [0x0000000117f12360+0x00000000000000b4]
J 1002 c1 java.lang.invoke.MemberName.checkForTypeAlias(Ljava/lang/Class;)V java.base@11 (168 bytes) @ 0x0000000117b3daf4 [0x0000000117b3d560+0x0000000000000594]
J 920 c1 java.lang.invoke.MemberName$Factory.resolve(BLjava/lang/invoke/MemberName;Ljava/lang/Class;Z)Ljava/lang/invoke/MemberName; java.base@11 (157 bytes) @ 0x0000000117b2151c [0x0000000117b21260+0x00000000000002bc]
J 986 c1 java.lang.invoke.MemberName$Factory.resolveOrFail(BLjava/lang/invoke/MemberName;Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/invoke/MemberName; java.base@11 (53 bytes) @ 0x0000000117b30f0c [0x0000000117b30e60+0x00000000000000ac]
J 5098 c1 java.lang.invoke.MethodHandles$Lookup.resolveOrFail(BLjava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MemberName; java.base@11 (48 bytes) @ 0x0000000118497704 [0x0000000118497320+0x00000000000003e4]
J 5592 c1 java.lang.invoke.MethodHandles$Lookup.findStatic(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle; java.base@11 (27 bytes) @ 0x0000000117cfa2b4 [0x0000000117cfa200+0x00000000000000b4]
j  co.elastic.apm.agent.bci.IndyBootstrap.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/ConstantCallSite;+143
j  jdk.internal.reflect.GeneratedMethodAccessor66.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+48 java.base@11
J 4481 c2 java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; java.base@11 (65 bytes) @ 0x000000011f15ee18 [0x000000011f15ece0+0x0000000000000138]
j  java.lang.IndyBootstrapDispatcher.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;+33 java.base@11
J 5559 c1 java.lang.invoke.DirectMethodHandle$Holder.invokeStatic(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; java.base@11 (20 bytes) @ 0x0000000117c641dc [0x0000000117c63d80+0x0000000000
00045c]
j  java.lang.invoke.DelegatingMethodHandle$Holder.delegate(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;+19 java.base@11
J 5308 c1 java.lang.invoke.BootstrapMethodInvoker.invoke(Ljava/lang/Class;Ljava/lang/invoke/MethodHandle;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object; java.base@11 (688 bytes) @ 0x00000001184a06bc [0x00000001
1849d060+0x000000000000365c]
J 5317 c1 java.lang.invoke.CallSite.makeSite(Ljava/lang/invoke/MethodHandle;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/invoke/CallSite; java.base@11 (91 bytes) @ 0x0000000117a96504 [0x0000000117a96460+0
x00000000000000a4]
J 4845 c1 java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(Ljava/lang/Class;Ljava/lang/invoke/MethodHandle;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/invoke/MemberName; java.base@11 (44 bytes) @
0x00000001183e32c4 [0x00000001183e3240+0x0000000000000084]
J 4844 c1 java.lang.invoke.MethodHandleNatives.linkCallSite(Ljava/lang/Object;ILjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/invoke/MemberName; java.base@11 (66 bytes) @ 0x00000001183e2c84 [0x00000001183e2800+0x0000000000000484]
v  ~StubRoutines::call_stub
V  [libjvm.dylib+0x3a588a]  JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, Thread*)+0x21a
V  [libjvm.dylib+0x3a5221]  JavaCalls::call_static(JavaValue*, Klass*, Symbol*, Symbol*, JavaCallArguments*, Thread*)+0xb1
V  [libjvm.dylib+0x6dba3f]  SystemDictionary::find_dynamic_call_site_invoker(Klass*, int, Handle, Symbol*, Symbol*, Handle*, Handle*, Thread*)+0x469
V  [libjvm.dylib+0x4ff088]  LinkResolver::resolve_dynamic_call(CallInfo&, int, Handle, Symbol*, Symbol*, Klass*, Thread*)+0x4e
V  [libjvm.dylib+0x4febe7]  LinkResolver::resolve_invokedynamic(CallInfo&, constantPoolHandle const&, int, Thread*)+0x199
V  [libjvm.dylib+0x3a0a24]  InterpreterRuntime::resolve_invokedynamic(JavaThread*)+0x120
V  [libjvm.dylib+0x3a0afe]  InterpreterRuntime::resolve_from_cache(JavaThread*, Bytecodes::Code)+0x70
j  org.springframework.web.context.support.GenericWebApplicationContext.initPropertySources()V+32
j  org.springframework.context.support.AbstractApplicationContext.prepareRefresh()V+110
[...]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying external-plugin-test on "real setup" fails with "Cannot ...
Trying external-plugin-test on "real setup" fails with "Cannot resolve type description for co.elastic.apm.agent.bci.classloading.LookupExposer".
Read more >
Felix Barnsteiner on Twitter: "MethodHandles.publicLookup() fails if ...
IndyBootstrap classloading problem · Issue #1450 · elastic/apm-agent-java. As reported in forum. Problem with 1.18.1(and current master branch) versions.
Read more >
JBoss classloading problem - hibernate - Stack Overflow
This particular issue is, I believe, caused by Hibernate trying to auto-locate the Hibernate Validator library on the classpath. The version of Validator ......
Read more >
Index (co.elastic.apm:elastic-apm-agent 1.21.0 API) - Javadoc.io
IndyBootstrap. Is called by java.lang. ... ClassLoader) - Method in class co.elastic.apm.agent.impl. ... Information about the originally thrown error.
Read more >
java/elastic/apm-agent-java/apm-agent-core/src ... - Program Talk
classloading · methodmatching · DynamicTransformerImpl.java · ElasticApmAgent.java · HelperClassManager.java · HelperHolder.java · IndyBootstrap.java.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found