Skip to content

GH-2425: Fix NPE in ACFactory.shutdownCompleted #2426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.rabbitmq.client.Address;
import com.rabbitmq.client.AddressResolver;
import com.rabbitmq.client.BlockedListener;
import com.rabbitmq.client.Method;
import com.rabbitmq.client.Recoverable;
import com.rabbitmq.client.RecoveryListener;
import com.rabbitmq.client.ShutdownListener;
Expand Down Expand Up @@ -660,15 +661,18 @@ protected final String getDefaultHostName() {

@Override
public void shutdownCompleted(ShutdownSignalException cause) {
int protocolClassId = cause.getReason().protocolClassId();
Method reason = cause.getReason();
int protocolClassId = RabbitUtils.CONNECTION_PROTOCOL_CLASS_ID_10;
if (reason != null) {
protocolClassId = reason.protocolClassId();
}
if (protocolClassId == RabbitUtils.CHANNEL_PROTOCOL_CLASS_ID_20) {
this.closeExceptionLogger.log(this.logger, "Shutdown Signal", cause);
getChannelListener().onShutDown(cause);
}
else if (protocolClassId == RabbitUtils.CONNECTION_PROTOCOL_CLASS_ID_10) {
getConnectionListener().onShutDown(cause);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1932,4 +1932,39 @@ void testResolver() throws Exception {
verify(mockConnectionFactory).newConnection(any(ExecutorService.class), eq(resolver), anyString());
}

@Test
void nullShutdownCause() {
com.rabbitmq.client.ConnectionFactory mockConnectionFactory = mock(com.rabbitmq.client.ConnectionFactory.class);
AbstractConnectionFactory cf = createConnectionFactory(mockConnectionFactory);
AtomicBoolean connShutDown = new AtomicBoolean();
cf.addConnectionListener(new ConnectionListener() {

@Override
public void onCreate(Connection connection) {
}

@Override
public void onShutDown(ShutdownSignalException signal) {
connShutDown.set(true);
}

});
AtomicBoolean chanShutDown = new AtomicBoolean();
cf.addChannelListener(new ChannelListener() {

@Override
public void onCreate(Channel channel, boolean transactional) {
}

@Override
public void onShutDown(ShutdownSignalException signal) {
chanShutDown.set(true);
}

});
cf.shutdownCompleted(new ShutdownSignalException(false, false, null, chanShutDown));
assertThat(connShutDown.get()).isTrue();
assertThat(chanShutDown.get()).isFalse();
}

}