fix npe in guava eventbus plugin (#559)

Co-authored-by: 熊哲源 <xiongzheyuan@shouqianba.com>
This commit is contained in:
xzyJavaX 2023-06-21 14:32:18 +08:00 committed by GitHub
parent 3497199f98
commit b72e984289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 2 deletions

View File

@ -11,6 +11,7 @@ Release Notes.
* Add RocketMQ 5.x plugin
* Fix the conflict between the logging kernel and the JDK threadpool plugin.
* Fix the thread safety bug of finishing operation for the span named "SpringCloudGateway/sendRequest"
* Fix NPE in guava-eventbus-plugin.
#### Documentation

View File

@ -34,7 +34,7 @@ public class EventBusDispatchInterceptor implements InstanceMethodsAroundInterce
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
final Object event = allArguments[0];
if (event != null) {
if (event != null && ContextManager.isActive()) {
allArguments[0] = EventWrapper.wrapEvent(event, ContextManager.capture());
}
}

View File

@ -54,6 +54,7 @@ public class EventBusDispatchInterceptorTest {
originalEventObj = new Object();
mockedContextManager = Mockito.mockStatic(ContextManager.class);
mockedContextManager.when(ContextManager::isActive).thenReturn(true);
mockedContextManager.when(ContextManager::capture).thenReturn(contextSnapshot);
}

View File

@ -15,7 +15,7 @@
# limitations under the License.
segmentItems:
- serviceName: guava-eventbus-scenario
segmentSize: ge 2
segmentSize: ge 3
segments:
- segmentId: not null
spans:
@ -66,4 +66,18 @@ segmentItems:
refType: CrossThread, parentSpanId: 0, parentTraceSegmentId: not null,
parentServiceInstance: not null, parentService: guava-eventbus-scenario,
traceId: not null }
- segmentId: not null
spans:
- operationName: Guava/EventBus/org.apache.skywalking.apm.testcase.guava.eventbus.service.SubscriberService/consumer
operationId: 0
parentSpanId: -1
spanId: 0
spanLayer: Unknown
startTime: nq 0
endTime: nq 0
componentId: 123
isError: false
spanType: Local
peer: ''
skipAnalysis: false
meterItems: []

View File

@ -46,6 +46,9 @@ public class CaseController {
asyncEventBus.register(subscriberService);
final TestEvent testEvent = new TestEvent();
testEvent.setContent("test");
final TestEvent testEvent2 = new TestEvent();
testEvent2.setContent("test2");
new Thread(() -> asyncEventBus.post(testEvent2)).start();
eventBus.post(testEvent);
testEvent.setAsyncContext(request.startAsync());
asyncEventBus.post(testEvent);