Prevent missing length from throwing an NPE.
[xudocci.git] / src / main / java / net / pterodactylus / irc / Connection.java
index 15dde44..b1ca64a 100644 (file)
@@ -511,6 +511,9 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                } catch (IOException ioe1) {
                        logger.log(Level.WARNING, "I/O error", ioe1);
                        eventBus.post(new ConnectionClosed(this, ioe1));
+               } catch (RuntimeException re1) {
+                       logger.log(Level.SEVERE, "Runtime error", re1);
+                       eventBus.post(new ConnectionClosed(this, re1));
                } finally {
                        established = false;
                        logger.info("Closing Connection.");
@@ -550,7 +553,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                                }
                        } else if (messageWords[1].equalsIgnoreCase("ACCEPT")) {
                                Optional<Integer> port = Optional.fromNullable(Ints.tryParse(messageWords[3]));
-                               long position = Optional.fromNullable(Longs.tryParse(messageWords[4])).or(-1L);
+                               long position = (messageWords.length > 4) ? Optional.fromNullable(Longs.tryParse(messageWords[4])).or(-1L) : -1;
                                if (port.isPresent()) {
                                        eventBus.post(new DccAcceptReceived(this, client, messageWords[2], port.get(), position));
                                } else {