Added NPE guard for null async executor; fixes gh-2094
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -26,6 +26,7 @@ import static java.util.regex.Pattern.compile;
|
||||
class SpanNameProvider {
|
||||
|
||||
private static final String DEFAULT_SPAN_NAME = "query";
|
||||
|
||||
private static final Pattern PATTERN_MATCHING_FIRST_WORD_OF_SQL = compile("^([a-zA-Z]+)[^a-zA-Z]?.*$");
|
||||
|
||||
String getSpanNameFor(String sql) {
|
||||
@@ -47,4 +48,5 @@ class SpanNameProvider {
|
||||
|
||||
return spanName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.jdbc;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -22,9 +23,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class SpanNameProviderTest {
|
||||
|
||||
private static final String DEFAULT_SPAN_NAME = "query";
|
||||
|
||||
private static final String SPAN_NAME_FOR_SELECTS = "select";
|
||||
|
||||
private static final String SPAN_NAME_FOR_UPDATES = "update";
|
||||
|
||||
private static final String SPAN_NAME_FOR_INSERTS = "insert";
|
||||
|
||||
private static final String SPAN_NAME_FOR_DELETES = "delete";
|
||||
|
||||
@Test
|
||||
@@ -124,4 +129,5 @@ public class SpanNameProviderTest {
|
||||
|
||||
assertThat(result).isEqualTo(expectedResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user