Bug 452665 - [jdt] Socket operation on nonsocket: configureBlocking

Make sure we don't initialize server socket with default port if we
don't get the address. This seem to cause "Socket operation on
nonsocket: configureBlocking" error later.

Still unclear how the null address could be passed to the service except
we are called from startListening() which according to the comment in
the code is not supported by JDT.

Change-Id: Ib4609212a0f06997fa7be4b7cd348c3b578ee699
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
diff --git a/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/connect/SocketTransportService.java b/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/connect/SocketTransportService.java
index f363e24..07455df 100644
--- a/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/connect/SocketTransportService.java
+++ b/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/connect/SocketTransportService.java
@@ -193,8 +193,9 @@
 		} catch (InterruptedException e1) {
 		}
 
-		if (handshakeCompleted[0])
+		if (handshakeCompleted[0]) {
 			return;
+		}
 
 		try {
 			in.close();
@@ -202,8 +203,9 @@
 		} catch (IOException e) {
 		}
 
-		if (ex[0] != null)
+		if (ex[0] != null) {
 			throw ex[0];
+		}
 
 		throw new TransportTimeoutException();
 	}
@@ -213,8 +215,9 @@
 			DataInputStream in = new DataInputStream(input);
 			byte[] handshakeInput = new byte[handshakeBytes.length];
 			in.readFully(handshakeInput);
-			if (!Arrays.equals(handshakeInput, handshakeBytes))
+			if (!Arrays.equals(handshakeInput, handshakeBytes)) {
 				throw new IOException("Received invalid handshake"); //$NON-NLS-1$
+			}
 		} catch (EOFException e) {
 			throw new ClosedConnectionException();
 		}
@@ -274,9 +277,10 @@
 	@Override
 	public ListenKey startListening(String address) throws IOException {
 		String host = null;
-		int port = 0; // jdt debugger will always specify an address in
-						// the form localhost:port
+		int port = -1;
 		if (address != null) {
+			// jdt debugger will always specify an address in
+			// the form localhost:port
 			String[] strings = address.split(":"); //$NON-NLS-1$
 			host = "localhost"; //$NON-NLS-1$
 			if (strings.length == 2) {
@@ -286,6 +290,9 @@
 				port = Integer.parseInt(strings[0]);
 			}
 		}
+		if (port == -1) {
+			throw new IOException("Unable to decode port from address: " + address); //$NON-NLS-1$
+		}
 		if (host == null) {
 			host = "localhost"; //$NON-NLS-1$
 		}