We upgraded our application from Spring Boot 3.4.2 to 3.4.3 and ever since doing that, tests that use ApplicationContextRunner
have become very flaky and produce this error:
Caused by: java.lang.NullPointerException: Cannot read field "generatedClass" because "data" is null
at org.springframework.cglib.proxy.Enhancer.nextInstance(Enhancer.java:783)
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:321)
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:562)
at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:407)
at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:169)
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:121)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:539)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:311)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:363)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:153)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:791)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:609)
The test itself is rather simple and is using ApplicationContextRunner
something like this:
var applicationContextRunner = new ApplicationContextRunner()
.withUserConfiguration(MyConfiguration.class)
.withBean(SimpleMeterRegistry);
MyConfiguration
is as follows:
@Configuration(proxyBeanMethods = false)
@ComponentScan(excludeFilters = @Filter(type = REGEX, pattern = ".*example\\.core\\.autoconfigure.*"))
@ConfigurationPropertiesScan
public class MyConfiguration {
}
It's to be noted that if the test is run on its own it never fails.