From 678785ba32eea32e61a67b075be90ef3a2f197c3 Mon Sep 17 00:00:00 2001 From: Lazar Kirchev Date: Mon, 24 Oct 2011 16:32:19 +0300 Subject: Fix NPE in TelnetCommand --- .../eclipse/equinox/console/telnet/TelnetCommand.java | 11 ++++++++--- .../org/eclipse/equinox/console/telnet/TelnetServer.java | 16 ++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetCommand.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetCommand.java index 5673a3035..2874c1b16 100755 --- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetCommand.java +++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetCommand.java @@ -165,7 +165,8 @@ public class TelnetCommand { telnetServer.start(); } else if ("stop".equals(command)) { if (telnetServer == null) { - throw new IllegalStateException("telnet is not running."); + System.out.println("telnet is not running."); + return; } telnetServer.stopTelnetServer(); @@ -175,12 +176,16 @@ public class TelnetCommand { public synchronized void addCommandProcessor(CommandProcessor processor) { processors.add(processor); - telnetServer.addCommandProcessor(processor); + if (telnetServer != null) { + telnetServer.addCommandProcessor(processor); + } } public synchronized void removeCommandProcessor(CommandProcessor processor) { processors.remove(processor); - telnetServer.removeCommandProcessor(processor); + if (telnetServer != null) { + telnetServer.removeCommandProcessor(processor); + } } private void printHelp() { diff --git a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetServer.java b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetServer.java index 3ea618918..9b7dd14b2 100755 --- a/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetServer.java +++ b/bundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetServer.java @@ -84,16 +84,20 @@ public class TelnetServer extends Thread { } public synchronized void addCommandProcessor(CommandProcessor processor) { - List telnetConnections = new ArrayList(); - for (Socket socket : sockets) { - TelnetConnection telnetConnection = new TelnetConnection(socket, processor, context); - telnetConnections.add(telnetConnection); - telnetConnection.start(); + processors.add(processor); + if (!sockets.isEmpty()) { + List telnetConnections = new ArrayList(); + for (Socket socket : sockets) { + TelnetConnection telnetConnection = new TelnetConnection(socket, processor, context); + telnetConnections.add(telnetConnection); + telnetConnection.start(); + } + processorToConnectionsMapping.put(processor, telnetConnections); } - processorToConnectionsMapping.put(processor, telnetConnections); } public synchronized void removeCommandProcessor(CommandProcessor processor) { + processors.remove(processor); List telnetConnections = processorToConnectionsMapping.remove(processor); if (telnetConnections != null) { for (TelnetConnection telnetConnection : telnetConnections) { -- cgit v1.2.3