Skip to content

Commit

Permalink
fix npe in guava eventbus plugin (#559)
Browse files Browse the repository at this point in the history
Co-authored-by: 熊哲源 <[email protected]>
  • Loading branch information
xzyJavaX and 熊哲源 committed Jun 21, 2023
1 parent 3497199 commit b72e984
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void setUp() throws Exception {
originalEventObj = new Object();

mockedContextManager = Mockito.mockStatic(ContextManager.class);
mockedContextManager.when(ContextManager::isActive).thenReturn(true);
mockedContextManager.when(ContextManager::capture).thenReturn(contextSnapshot);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
segmentItems:
- serviceName: guava-eventbus-scenario
segmentSize: ge 2
segmentSize: ge 3
segments:
- segmentId: not null
spans:
Expand Down Expand Up @@ -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: []
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public void testcase(HttpServletRequest request) throws Exception {
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);
Expand Down

0 comments on commit b72e984

Please sign in to comment.