Prevent NPE on closing.
[xudocci.git] / src / main / java / net / pterodactylus / irc / Connection.java
index b1ca64a..f48b205 100644 (file)
@@ -59,6 +59,7 @@ import net.pterodactylus.irc.event.NicknameInUseReceived;
 import net.pterodactylus.irc.event.NoNicknameGivenReceived;
 import net.pterodactylus.irc.event.PrivateMessageReceived;
 import net.pterodactylus.irc.event.PrivateNoticeReceived;
+import net.pterodactylus.irc.event.ReplyReceived;
 import net.pterodactylus.irc.event.UnknownReplyReceived;
 import net.pterodactylus.irc.util.RandomNickname;
 import net.pterodactylus.xdcc.util.io.BandwidthCountingInputStream;
@@ -324,7 +325,9 @@ public class Connection extends AbstractExecutionThreadService implements Servic
         *              if an I/O error occurs
         */
        public void close() throws IOException {
-               connectionHandler.close();
+               if (connectionHandler != null) {
+                       connectionHandler.close();
+               }
        }
 
        //
@@ -373,6 +376,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic
 
                        while (connected) {
                                Reply reply = connectionHandler.readReply();
+                               eventBus.post(new ReplyReceived(this, reply));
                                logger.finest(String.format("<< %s", reply));
                                String command = reply.command();
                                List<String> parameters = reply.parameters();