spring-cloud / spring-cloud-circuitbreaker

Spring Cloud Circuit Breaker API and Implementations
Apache License 2.0
328 stars 109 forks source link

NullPointerException with 2021.0.4 with deprecated Resilience4JCircuitBreakerFactory() #156

Closed jeantichoc closed 1 year ago

jeantichoc commented 1 year ago

Describe the bug

Going from Spring Cloud 2021.0.3 to 2021.0.4, we are experiencing NullPointerException while dealing with CircuitBreaker. I think it's because we are still using a deprecated constructor new Resilience4JCircuitBreakerFactory() (I know, I know, we are lazy)

It's seems that the old deprecated constructor miss a initialisation for resilience4JConfigurationProperties. https://github.com/spring-cloud/spring-cloud-circuitbreaker/compare/v2.1.3...v2.1.4#diff-9e9e0c4db217f6f67874b64ac5b3b3cf581ade2ab93cc9456d7156d2207e359d

Sample

[2022-09-21T11:11:02.395Z] Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '***Consumer' defined in ****.config.*****ConsumerConfig: Unsatisfied dependency expressed through method '***Consumer' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***CircuitBreaker' defined in ***.config.****ConsumerConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.client.circuitbreaker.CircuitBreaker]: Factory method '***CircuitBreaker' threw exception; nested exception is java.lang.NullPointerException
[2022-09-21T11:11:02.395Z]  at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
[2022-09-21T11:11:02.395Z]  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
[2022-09-21T11:11:02.395Z]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
[2022-09-21T11:11:02.395Z]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
[2022-09-21T11:11:02.396Z]  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
[2022-09-21T11:11:02.396Z]  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
[2022-09-21T11:11:02.396Z]  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
[2022-09-21T11:11:02.396Z]  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734)
[2022-09-21T11:11:02.396Z]  at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
[2022-09-21T11:11:02.396Z]  at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
[2022-09-21T11:11:02.396Z]  at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:132)
[2022-09-21T11:11:02.396Z]  at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
[2022-09-21T11:11:02.396Z]  at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
[2022-09-21T11:11:02.396Z]  ... 68 common frames omitted
[2022-09-21T11:11:02.396Z] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***CircuitBreaker' defined in ***.config.***ConsumerConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.client.circuitbreaker.CircuitBreaker]: Factory method '***CircuitBreaker' threw exception; nested exception is java.lang.NullPointerException
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
[2022-09-21T11:11:02.396Z]  ... 87 common frames omitted
[2022-09-21T11:11:02.396Z] Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.client.circuitbreaker.CircuitBreaker]: Factory method '***CircuitBreaker' threw exception; nested exception is java.lang.NullPointerException
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
[2022-09-21T11:11:02.396Z]  at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
[2022-09-21T11:11:02.396Z]  ... 101 common frames omitted
[2022-09-21T11:11:02.396Z] Caused by: java.lang.NullPointerException: null
[2022-09-21T11:11:02.396Z]  at org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JCircuitBreakerFactory.create(Resilience4JCircuitBreakerFactory.java:138)
[2022-09-21T11:11:02.396Z]  at org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JCircuitBreakerFactory.create(Resilience4JCircuitBreakerFactory.java:116)
ryanjbaxter commented 1 year ago

You mean this constructor correct? https://github.com/spring-cloud/spring-cloud-circuitbreaker/compare/v2.1.3...v2.1.4#diff-9e9e0c4db217f6f67874b64ac5b3b3cf581ade2ab93cc9456d7156d2207e359dR59

jeantichoc commented 1 year ago

You mean this constructor correct? v2.1.3...v2.1.4#diff-9e9e0c4db217f6f67874b64ac5b3b3cf581ade2ab93cc9456d7156d2207e359dR59

Yes, this is the one we are using at a lot of different places 😅

ryanjbaxter commented 1 year ago

@jeantichoc check out this PR and see if it looks good https://github.com/spring-cloud/spring-cloud-circuitbreaker/pull/157

jeantichoc commented 1 year ago

yes, that's what I had in mind, and it's seems to work fine, wasn't sure about setting the Resilience4jBulkheadProvider to null, I have to read more documentation, but I saw some null check at some places so I guess it could work as before with this :)

jeantichoc commented 1 year ago

Thanks @ryanjbaxter !

ryanjbaxter commented 1 year ago

No problem thanks for opening the issue!

Just an FYI I removed all deprecated constructors in the main branch.

jeantichoc commented 1 year ago

No problem thanks for opening the issue!

Just an FYI I removed all deprecated constructors in the main branch.

Perfect! We will rework/rethink our circuit breaker management accordingly. There's some new features we missed since our first implemention 🙂

ryanjbaxter commented 1 year ago

Why did you reopen the issue?

jeantichoc commented 1 year ago

Very sorry, I leave my phone to my nephew for 1 minute, and he seems to want to experiment with GitHub 🥲.