Added NPE guard for null async executor; fixes gh-2094

This commit is contained in:
Marcin Grzejszczak
2022-01-03 14:27:14 +01:00
parent 818f61f09e
commit 011eb938ac
2 changed files with 16 additions and 3 deletions

View File

@@ -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

View File

@@ -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();
}
}