diff options
author | Lazar Kirchev | 2011-10-24 13:32:19 +0000 |
---|---|---|
committer | Lazar Kirchev | 2011-10-24 13:32:19 +0000 |
commit | 678785ba32eea32e61a67b075be90ef3a2f197c3 (patch) | |
tree | 1c9ee654c37b25339c4097a6ea73d94d35047782 | |
parent | 8fd8d14ca98e277eea6bb7020285c155e183dcdc (diff) | |
download | rt.equinox.bundles-678785ba32eea32e61a67b075be90ef3a2f197c3.tar.gz rt.equinox.bundles-678785ba32eea32e61a67b075be90ef3a2f197c3.tar.xz rt.equinox.bundles-678785ba32eea32e61a67b075be90ef3a2f197c3.zip |
Fix NPE in TelnetCommand
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<TelnetConnection> telnetConnections = new ArrayList<TelnetConnection>(); - for (Socket socket : sockets) { - TelnetConnection telnetConnection = new TelnetConnection(socket, processor, context); - telnetConnections.add(telnetConnection); - telnetConnection.start(); + processors.add(processor); + if (!sockets.isEmpty()) { + List<TelnetConnection> telnetConnections = new ArrayList<TelnetConnection>(); + 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<TelnetConnection> telnetConnections = processorToConnectionsMapping.remove(processor); if (telnetConnections != null) { for (TelnetConnection telnetConnection : telnetConnections) { |