summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLazar Kirchev2011-10-24 09:39:03 (EDT)
committerLazar Kirchev2011-10-24 09:39:03 (EDT)
commit0eee480ccde8b5a9b1408c1487ad91768ff49129 (patch)
tree31c9bc231025062a35438ffb0e44ebc14c22af7b
parent985faa15f03ad567dde4bf0525228c5724fa4cd6 (diff)
downloadrt.equinox.incubator-0eee480ccde8b5a9b1408c1487ad91768ff49129.zip
rt.equinox.incubator-0eee480ccde8b5a9b1408c1487ad91768ff49129.tar.gz
rt.equinox.incubator-0eee480ccde8b5a9b1408c1487ad91768ff49129.tar.bz2
Fix NPE in TelnetCommand
-rw-r--r--console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/ssh/SshCommand.java11
-rw-r--r--console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/telnet/TelnetCommand.java11
-rw-r--r--console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/telnet/TelnetServer.java16
3 files changed, 26 insertions, 12 deletions
diff --git a/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/ssh/SshCommand.java b/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/ssh/SshCommand.java
index 136509a..83557a5 100644
--- a/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/ssh/SshCommand.java
+++ b/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/ssh/SshCommand.java
@@ -194,7 +194,8 @@ public class SshCommand {
}
} else if ("stop".equals(command)) {
if (sshServ == null) {
- throw new IllegalStateException("ssh is not running.");
+ System.out.println("ssh is not running.");
+ return;
}
sshServ.stopSshServer();
@@ -204,12 +205,16 @@ public class SshCommand {
public synchronized void addCommandProcessor(CommandProcessor processor) {
processors.add(processor);
- sshServ.addCommandProcessor(processor);
+ if (sshServ != null) {
+ sshServ.addCommandProcessor(processor);
+ }
}
public synchronized void removeCommandProcessor(CommandProcessor processor) {
processors.remove(processor);
- sshServ.removeCommandProcessor(processor);
+ if (sshServ != null) {
+ sshServ.removeCommandProcessor(processor);
+ }
}
private void checkPortAvailable(int port) throws Exception {
diff --git a/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/telnet/TelnetCommand.java b/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/telnet/TelnetCommand.java
index 5673a30..2874c1b 100644
--- a/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/telnet/TelnetCommand.java
+++ b/console/org.eclipse.equinox.console.supportability/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/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/telnet/TelnetServer.java b/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/telnet/TelnetServer.java
index 3ea6189..9b7dd14 100644
--- a/console/org.eclipse.equinox.console.supportability/src/org/eclipse/equinox/console/telnet/TelnetServer.java
+++ b/console/org.eclipse.equinox.console.supportability/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) {