aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLazar Kirchev2011-10-24 09:32:19 (EDT)
committerLazar Kirchev2011-10-24 09:32:19 (EDT)
commit678785ba32eea32e61a67b075be90ef3a2f197c3 (patch)
tree1c9ee654c37b25339c4097a6ea73d94d35047782
parent8fd8d14ca98e277eea6bb7020285c155e183dcdc (diff)
downloadrt.equinox.bundles-678785ba32eea32e61a67b075be90ef3a2f197c3.zip
rt.equinox.bundles-678785ba32eea32e61a67b075be90ef3a2f197c3.tar.gz
rt.equinox.bundles-678785ba32eea32e61a67b075be90ef3a2f197c3.tar.bz2
Fix NPE in TelnetCommand
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetCommand.java11
-rwxr-xr-xbundles/org.eclipse.equinox.console/src/org/eclipse/equinox/console/telnet/TelnetServer.java16
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 5673a30..2874c1b 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 3ea6189..9b7dd14 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) {