avoiding NPE on PingRunnable

This commit is contained in:
Clebert Suconic 2016-02-01 17:19:14 -05:00 committed by jbertram
parent 64faaada98
commit c982b1fa40
1 changed files with 12 additions and 7 deletions

View File

@ -843,11 +843,14 @@ public class ClientSessionFactoryImpl implements ClientSessionFactoryInternal, C
} }
private void checkCloseConnection() { private void checkCloseConnection() {
if (connection != null && sessions.size() == 0) { RemotingConnection connectionInUse = connection;
Connector connectorInUse = connector;
if (connectionInUse != null && sessions.size() == 0) {
cancelScheduledTasks(); cancelScheduledTasks();
try { try {
connection.destroy(); connectionInUse.destroy();
} }
catch (Throwable ignore) { catch (Throwable ignore) {
} }
@ -855,8 +858,8 @@ public class ClientSessionFactoryImpl implements ClientSessionFactoryInternal, C
connection = null; connection = null;
try { try {
if (connector != null) { if (connectorInUse != null) {
connector.close(); connectorInUse.close();
} }
} }
catch (Throwable ignore) { catch (Throwable ignore) {
@ -1207,8 +1210,10 @@ public class ClientSessionFactoryImpl implements ClientSessionFactoryInternal, C
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (clientFailureCheckPeriod != -1 && connectionTTL != -1 && now >= lastCheck + connectionTTL) { final RemotingConnection connectionInUse = connection;
if (!connection.checkDataReceived()) {
if (connectionInUse != null && clientFailureCheckPeriod != -1 && connectionTTL != -1 && now >= lastCheck + connectionTTL) {
if (!connectionInUse.checkDataReceived()) {
// We use a different thread to send the fail // We use a different thread to send the fail
// but the exception has to be created here to preserve the stack trace // but the exception has to be created here to preserve the stack trace
@ -1220,7 +1225,7 @@ public class ClientSessionFactoryImpl implements ClientSessionFactoryInternal, C
// Must be executed on different thread // Must be executed on different thread
@Override @Override
public void run() { public void run() {
connection.fail(me); connectionInUse.fail(me);
} }
}); });