From 028529b8a910af3d1d8c941c48184d1730ae4973 Mon Sep 17 00:00:00 2001 From: jbertram Date: Wed, 29 Apr 2015 13:35:18 -0500 Subject: [PATCH] Avoid potential NPEs seen on tests --- .../test/minimalserver/MinimalServer.java | 11 ++++- .../remoting/impl/netty/NettyAcceptor.java | 46 +++++++++++-------- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalServer.java b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalServer.java index 5c43d6f60d..8351396b54 100644 --- a/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalServer.java +++ b/artemis-protocols/artemis-proton-plug/src/test/java/org/proton/plug/test/minimalserver/MinimalServer.java @@ -155,8 +155,15 @@ public class MinimalServer public synchronized void stop() { - serverChannelGroup.close().awaitUninterruptibly(); - ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly(); + if (serverChannelGroup != null) + { + serverChannelGroup.close().awaitUninterruptibly(); + } + + if (channelGroup != null) + { + ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly(); + } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java index 02342f798a..8ed06be4eb 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java @@ -546,19 +546,26 @@ public class NettyAcceptor implements Acceptor // serverChannelGroup has been unbound in pause() - serverChannelGroup.close().awaitUninterruptibly(); - ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly(); - - if (!future.isSuccess()) + if (serverChannelGroup != null) { - ActiveMQServerLogger.LOGGER.nettyChannelGroupError(); - Iterator iterator = future.group().iterator(); - while (iterator.hasNext()) + serverChannelGroup.close().awaitUninterruptibly(); + } + + if (channelGroup != null) + { + ChannelGroupFuture future = channelGroup.close().awaitUninterruptibly(); + + if (!future.isSuccess()) { - Channel channel = iterator.next(); - if (channel.isActive()) + ActiveMQServerLogger.LOGGER.nettyChannelGroupError(); + Iterator iterator = future.group().iterator(); + while (iterator.hasNext()) { - ActiveMQServerLogger.LOGGER.nettyChannelStillOpen(channel, channel.remoteAddress()); + Channel channel = iterator.next(); + if (channel.isActive()) + { + ActiveMQServerLogger.LOGGER.nettyChannelStillOpen(channel, channel.remoteAddress()); + } } } } @@ -617,17 +624,20 @@ public class NettyAcceptor implements Acceptor } // We *pause* the acceptor so no new connections are made - ChannelGroupFuture future = serverChannelGroup.close().awaitUninterruptibly(); - if (!future.isSuccess()) + if (serverChannelGroup != null) { - ActiveMQServerLogger.LOGGER.nettyChannelGroupBindError(); - Iterator iterator = future.group().iterator(); - while (iterator.hasNext()) + ChannelGroupFuture future = serverChannelGroup.close().awaitUninterruptibly(); + if (!future.isSuccess()) { - Channel channel = iterator.next(); - if (channel.isActive()) + ActiveMQServerLogger.LOGGER.nettyChannelGroupBindError(); + Iterator iterator = future.group().iterator(); + while (iterator.hasNext()) { - ActiveMQServerLogger.LOGGER.nettyChannelStillBound(channel, channel.remoteAddress()); + Channel channel = iterator.next(); + if (channel.isActive()) + { + ActiveMQServerLogger.LOGGER.nettyChannelStillBound(channel, channel.remoteAddress()); + } } } }