We're encountering a java.lang.VerifyError when using classes instrumented by the Jacoco runtime agent, for classes loaded by Spring using Kotlin coroutines.
Environment details below:- Jacoco 0.8.7
- Kotlin 1.5.30 (also tested with 1.4.x - no problems)
- Java 11 (Corretto, 11.0.11)
- Alpine Linux 3.12 in a Docker Container
- kotlinx-coroutines-reactive 1.3.8
- Spring Boot 2.3.12
- Spring Webflux 5.2.15
Class failing to verify is as follows:
@RestController
@RequestMapping("/my-service")
@ResponseBody
class StatusController() {
@GetMapping(path = ["/service-status"])
suspend fun getServiceStatus(): String {
return getRealStatus() + "2"
}
suspend fun getRealStatus(): String {
return "1"
}
}
Stack track included below:
2021-08-27T19:03:58,262 +0000 [main] WARN org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webHandler' defined in class path resource [org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.example.myservice.controller.StatusController] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@38e7ed69]
2021-08-27T19:03:58,411 +0000 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webHandler' defined in class path resource [org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.example.myservice.controller.StatusController] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@38e7ed69]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:62)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:755)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:402)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)
at com.example.myservice.MyApplicationKt.main(myserviceApplication.kt:18)
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.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.example.myservice.controller.StatusController] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@38e7ed69]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:624)
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1251)
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:378)
at org.springframework.web.reactive.DispatcherHandler.initStrategies(DispatcherHandler.java:116)
at org.springframework.web.reactive.DispatcherHandler.setApplicationContext(DispatcherHandler.java:111)
at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:123)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:100)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:415)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1791)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
... 23 more
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.example.myservice.controller.StatusController] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@38e7ed69]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358)
at org.springframework.core.MethodIntrospector.selectMethods(MethodIntrospector.java:72)
at org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:206)
at org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:189)
at org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:157)
at org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:126)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1858)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1795)
... 39 more
Caused by: java.lang.VerifyError: Inconsistent stackmap frames at branch target 1336
Exception Details:
Location:
com/example/myservice/controller/StatusController.getServiceStatus$suspendImpl(Lcom/example/myservice/controller/StatusController;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @1316: goto
Reason:
Current frame's stack size doesn't match stackmap.
Current Frame:
bci: @1316
flags: { }
locals: { 'com/example/myservice/controller/StatusController', 'kotlin/coroutines/Continuation', 'com/newrelic/agent/bridge/ExitTracer', integer, null, top, top, top, top, top, top, 'kotlin/coroutines/Continuation', 'com/example/myservice/controller/StatusController', integer, null, top, top, top, top, top, top, 'kotlin/coroutines/Continuation', 'com/example/myservice/controller/StatusController', '[Z', 'com/example/myservice/controller/StatusController$getServiceStatus$1', 'java/lang/Object', 'java/lang/Object' }
stack: { 'java/lang/String' }
Stackmap Frame:
bci: @1336
flags: { }
locals: { 'com/example/myservice/controller/StatusController', 'kotlin/coroutines/Continuation', 'com/newrelic/agent/bridge/ExitTracer', integer, null, top, top, top, top, top, top, 'kotlin/coroutines/Continuation', 'com/example/myservice/controller/StatusController', integer, null, top, top, top, top, top, top, 'kotlin/coroutines/Continuation', 'com/example/myservice/controller/StatusController', '[Z', 'com/example/myservice/controller/StatusController$getServiceStatus$1', 'java/lang/Object', 'java/lang/Object' }
stack: { 'java/lang/Object', 'java/lang/Object' }
Bytecode:
0000000: 014d b200 5401 1019 0110 06b9 005a 0500
0000010: 4da7 0004 5703 3e01 3a04 b800 5e03 b900
0000020: 6402 003a 0519 05c6 01ec 1266 5712 0312
0000030: 6605 bd00 0559 0312 6753 5904 04bd 0069
0000040: 5903 126a 5353 b800 f1c0 0066 3a06 013a
0000050: 0719 06c6 0016 1906 b900 7301 0019 06b9
0000060: 0075 0100 b800 7b3a 0712 6657 01c6 0038
0000070: 1266 5701 c000 663a 0819 08b9 0073 0100
0000080: 1908 b900 7501 00b8 007b 3a09 1905 1908
0000090: b900 7f01 0019 0719 09b8 0085 b600 8bb8
00000a0: 008f a701 7112 9157 01c6 003b 1291 5701
00000b0: c000 913a 0819 08b9 0092 0100 1908 b900
00000c0: 9301 00b8 007b 3a09 1905 04bd 0095 5903
00000d0: b200 9953 1907 1909 b800 85b6 008b b800
00000e0: 8fa7 0132 129b 5701 c600 3b12 9b57 01c0
00000f0: 009b 3a08 1908 b900 9c01 0019 08b9 009d
0000100: 0100 b800 7b3a 0919 0504 bd00 9559 03b2
0000110: 00a0 5319 0719 09b8 0085 b600 8bb8 008f
0000120: a700 f312 a257 01c6 003b 12a2 5701 c000
0000130: a23a 0819 08b9 00a3 0100 1908 b900 a401
0000140: 00b8 007b 3a09 1905 04bd 0095 5903 b200
0000150: a753 1907 1909 b800 85b6 008b b800 8fa7
0000160: 00b4 12a9 5701 c600 3b12 a957 01c0 00a9
0000170: 3a08 1908 b900 aa01 0019 08b9 00ab 0100
0000180: b800 7b3a 0919 0504 bd00 9559 03b2 00ae
0000190: 5319 0719 09b8 0085 b600 8bb8 008f a700
00001a0: 7512 b057 1203 12b0 05bd 0005 5903 12b1
00001b0: 5359 0404 bd00 6959 0312 b253 53b8 00f4
00001c0: c600 5312 b057 1203 12b0 05bd 0005 5903
00001d0: 12b1 5359 0404 bd00 6959 0312 b253 53b8
00001e0: 00f7 c000 b03a 0819 08b9 00b9 0100 1908
00001f0: b900 ba01 00b8 007b 3a09 1905 04bd 0095
0000200: 5903 b200 bd53 1907 1909 b800 85b6 008b
0000210: b800 8fa7 0016 3a0a b200 5419 0a12 beb9
0000220: 00c2 0300 a700 0304 3e2a 2b3a 0b3a 0c03
0000230: 360d 013a 0eb8 005e 03b9 0064 0200 3a0f
0000240: 190f c601 ec12 6657 1203 1266 05bd 0005
0000250: 5903 1267 5359 0404 bd00 6959 0312 6a53
0000260: 53b8 00fa c000 663a 1001 3a11 1910 c600
0000270: 1619 10b9 0073 0100 1910 b900 7501 00b8
0000280: 007b 3a11 1266 5701 c600 3812 6657 01c0
0000290: 0066 3a12 1912 b900 7301 0019 12b9 0075
00002a0: 0100 b800 7b3a 1319 0f19 12b9 007f 0100
00002b0: 1911 1913 b800 85b6 008b b800 8fa7 0171
00002c0: 1291 5701 c600 3b12 9157 01c0 0091 3a12
00002d0: 1912 b900 9201 0019 12b9 0093 0100 b800
00002e0: 7b3a 1319 0f04 bd00 9559 03b2 0099 5319
00002f0: 1119 13b8 0085 b600 8bb8 008f a701 3212
0000300: 9b57 01c6 003b 129b 5701 c000 9b3a 1219
0000310: 12b9 009c 0100 1912 b900 9d01 00b8 007b
0000320: 3a13 190f 04bd 0095 5903 b200 a053 1911
0000330: 1913 b800 85b6 008b b800 8fa7 00f3 12a2
0000340: 5701 c600 3b12 a257 01c0 00a2 3a12 1912
0000350: b900 a301 0019 12b9 00a4 0100 b800 7b3a
0000360: 1319 0f04 bd00 9559 03b2 00a7 5319 1119
0000370: 13b8 0085 b600 8bb8 008f a700 b412 a957
0000380: 01c6 003b 12a9 5701 c000 a93a 1219 12b9
0000390: 00aa 0100 1912 b900 ab01 00b8 007b 3a13
00003a0: 190f 04bd 0095 5903 b200 ae53 1911 1913
00003b0: b800 85b6 008b b800 8fa7 0075 12b0 5712
00003c0: 0312 b005 bd00 0559 0312 b153 5904 04bd
00003d0: 0069 5903 12b2 5353 b800 fdc6 0053 12b0
00003e0: 5712 0312 b005 bd00 0559 0312 b153 5904
00003f0: 04bd 0069 5903 12b2 5353 b801 00c0 00b0
0000400: 3a12 1912 b900 b901 0019 12b9 00ba 0100
0000410: b800 7b3a 1319 0f04 bd00 9559 03b2 00bd
0000420: 5319 1119 13b8 0085 b600 8bb8 008f a700
0000430: 173a 14b2 0054 1914 12be b900 c203 00a7
0000440: 0003 0436 0d19 0c19 0b3a 153a 1612 2fc0
0000450: 0031 3a17 1915 c100 259a 000b 1917 0504
0000460: 54a7 0033 1915 c000 253a 1819 18b4 0104
0000470: 1301 057e 9a00 0b19 1706 0454 a700 1819
0000480: 1859 b401 0413 0105 64b5 0104 1917 0704
0000490: 54a7 0015 bb00 2559 1916 1915 b701 083a
00004a0: 1819 1708 0454 1918 b401 0b3a 19b8 0111
00004b0: 1917 1006 0454 3a1a 1918 b401 04aa 0000
00004c0: 0000 006a 0000 0000 0000 0001 0000 0017
00004d0: 0000 004f 1919 b801 1719 1710 0704 5419
00004e0: 1619 1819 1804 b501 04b6 0119 5919 1aa5
00004f0: 000c 1917 1008 0454 a700 2119 1710 0904
0000500: 5419 1a19 1710 0a04 54a7 002f 1919 b801
0000510: 1719 1919 1710 0b04 54ba 0125 0000 1917
0000520: 100c 0454 a700 14bb 0127 5913 0129 b701
0000530: 2c19 1710 0d04 54bf 3a0e 0315 0d9f 0008
0000540: 190e a700 1e19 0ea7 0019 3a14 b200 5419
0000550: 1412 beb9 00c2 0300 a700 0319 0ea7 0003
0000560: 3a04 031d 9f00 1419 042c c600 0d2c 1100
0000570: b001 b900 d503 00b0 1904 2cc6 000d 2c11
0000580: 00b0 01b9 00d5 0300 b03a 0ab2 0054 190a
0000590: 12be b900 c203 00a7 0003 1904 2cc6 000d
00005a0: 2c11 00b0 01b9 00d5 0300 b02c c600 0b59
00005b0: 2c5f b900 d802 00bf
Exception Handler Table:
bci [2, 21] => handler: 20
bci [565, 1073] => handler: 1073
bci [1349, 1354] => handler: 1354
bci [26, 534] => handler: 534
bci [1400, 1417] => handler: 1417
bci [2, 1451] => handler: 1451
Stackmap Table:
full_frame(@20,{Object[#3],Object[#236],Object[#209]},{Object[#78]})
same_frame(@21)
full_frame(@105,{Object[#3],Object[#236],Object[#209],Integer,Null,Object[#238],Object[#102],Object[#105]},{})
same_frame(@165)
same_frame(@228)
same_frame(@291)
same_frame(@354)
same_frame(@417)
chop_frame(@531,2)
full_frame(@534,{Object[#3],Object[#236],Object[#209],Integer,Null},{Object[#78]})
full_frame(@551,{Object[#3],Object[#236],Object[#209],Integer,Null,Top,Top,Top,Top,Top,Object[#78]},{})
full_frame(@553,{Object[#3],Object[#236],Object[#209],Integer,Null},{})
full_frame(@644,{Object[#3],Object[#236],Object[#209],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Null,Object[#238],Object[#102],Object[#105]},{})
same_frame(@704)
same_frame(@767)
same_frame(@830)
same_frame(@893)
same_frame(@956)
chop_frame(@1070,2)
full_frame(@1073,{Object[#3],Object[#236],Object[#209],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Null},{Object[#78]})
full_frame(@1090,{Object[#3],Object[#236],Object[#209],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Null,Top,Top,Top,Top,Top,Object[#78]},{})
full_frame(@1093,{Object[#3],Object[#236],Object[#209],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Null},{})
full_frame(@1124,{Object[#3],Object[#236],Object[#209],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Object[#49]},{})
append_frame(@1151,Object[#37])
chop_frame(@1172,1)
append_frame(@1190,Object[#37])
append_frame(@1236,Object[#5],Object[#5])
same_locals_1_stack_item_frame(@1275,Object[#5])
same_frame(@1292)
same_locals_1_stack_item_frame(@1305,Object[#5])
same_frame(@1319)
full_frame(@1336,{Object[#3],Object[#236],Object[#209],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Object[#49],Object[#37],Object[#5],Object[#5]},{Object[#5],Object[#5]})
full_frame(@1349,{Object[#3],Object[#236],Object[#209],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Object[#5],Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Object[#49],Object[#37],Object[#5],Object[#5]},{Object[#5]})
same_locals_1_stack_item_frame(@1354,Object[#78])
full_frame(@1371,{Object[#3],Object[#236],Object[#209],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Object[#5],Top,Top,Top,Top,Top,Object[#78],Object[#236],Object[#3],Object[#49],Object[#37],Object[#5],Object[#5]},{})
full_frame(@1376,{Object[#3],Object[#236],Object[#209],Integer,Null,Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Object[#5],Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Object[#49],Object[#37],Object[#5],Object[#5]},{Object[#5],Object[#5]})
full_frame(@1399,{Object[#3],Object[#236],Object[#209],Integer,Object[#5],Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Object[#5],Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Object[#49],Object[#37],Object[#5],Object[#5]},{Object[#5],Object[#5]})
same_locals_1_stack_item_frame(@1400,Object[#5])
full_frame(@1416,{Object[#3],Object[#236],Object[#209],Integer,Object[#5],Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Integer,Object[#5],Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Object[#49],Object[#37],Object[#5],Object[#5]},{Object[#5],Object[#5]})
same_locals_1_stack_item_frame(@1417,Object[#78])
full_frame(@1434,{Object[#3],Object[#236],Object[#209],Integer,Object[#5],Top,Top,Top,Top,Top,Object[#78],Object[#236],Object[#3],Integer,Object[#5],Top,Top,Top,Top,Top,Top,Object[#236],Object[#3],Object[#49],Object[#37],Object[#5],Object[#5]},{})
same_locals_1_stack_item_frame(@1450,Object[#5])
full_frame(@1451,{Object[#3],Object[#236],Object[#209]},{Object[#78]})
same_locals_1_stack_item_frame(@1463,Object[#78])
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)
... 47 more
Things we've tried:
- Removing Jacoco agent - application works without issue
- Using Jacoco 0.8.8-SNAPSHOT, revision 35b986af3bfe16ff26ea89ae478ed174e7b01e1f - no change in problem
- Using Kotlin 1.4.x - application works without issue
- Removing coroutine module and usage - application works without issue
Any help appreciated. The setup is complicated enough that it's non-trivial to make a sample app outside my company's ecology, but if it looks like a real bug I can try to muster one.