diff --git a/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceAsyncCustomizer.java b/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceAsyncCustomizer.java index e7db11f4e..21d80a42c 100644 --- a/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceAsyncCustomizer.java +++ b/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceAsyncCustomizer.java @@ -44,10 +44,14 @@ public class LazyTraceAsyncCustomizer extends AsyncConfigurerSupport { @Override public Executor getAsyncExecutor() { - if (this.delegate.getAsyncExecutor() instanceof LazyTraceExecutor) { - return this.delegate.getAsyncExecutor(); + Executor executor = this.delegate.getAsyncExecutor(); + if (executor instanceof LazyTraceExecutor) { + return executor; } - return LazyTraceExecutor.wrap(this.beanFactory, this.delegate.getAsyncExecutor()); + else if (executor == null) { + return null; + } + return LazyTraceExecutor.wrap(this.beanFactory, executor); } @Override diff --git a/spring-cloud-sleuth-instrumentation/src/test/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceAsyncCustomizerTest.java b/spring-cloud-sleuth-instrumentation/src/test/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceAsyncCustomizerTest.java index 48a3d0fad..2e08a89f5 100644 --- a/spring-cloud-sleuth-instrumentation/src/test/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceAsyncCustomizerTest.java +++ b/spring-cloud-sleuth-instrumentation/src/test/java/org/springframework/cloud/sleuth/instrument/async/LazyTraceAsyncCustomizerTest.java @@ -54,4 +54,13 @@ public class LazyTraceAsyncCustomizerTest { BDDAssertions.then(executor).isExactlyInstanceOf(LazyTraceExecutor.class); } + @Test + public void should_return_null_when_executor_null() throws Exception { + BDDMockito.given(this.asyncConfigurer.getAsyncExecutor()).willReturn(null); + + Executor executor = this.lazyTraceAsyncCustomizer.getAsyncExecutor(); + + BDDAssertions.then(executor).isNull(); + } + }