11diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ConnectionSpec.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ConnectionSpec.java
2- index 9ab389564c..9b7c044c81 100644
2+ index bb8a4e8183..b9662fe6cd 100644
33--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ConnectionSpec.java
44+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ConnectionSpec.java
55@@ -25,7 +25,7 @@ import java.io.OutputStream;
@@ -86,11 +86,10 @@ index 9ab389564c..9b7c044c81 100644
8686 } catch (IOException ex) {
8787 if (isClosed(server)) {
8888 break;
89- @@ -129,26 +152,54 @@ final class ConnectionSpec implements Closeable {
90- }
89+ @@ -130,25 +153,53 @@ final class ConnectionSpec implements Closeable {
9190 };
9291 listeningThread.start();
93- - out.write((prefix + " listening at port " + localPort).getBytes());
92+ out.write((prefix + " listening at port " + localPort + "\n" ).getBytes());
9493+ StringBuilder message = new StringBuilder();
9594+ message.append(prefix).append(" listening at port ").append(localPort);
9695+ if (hash) {
@@ -128,7 +127,6 @@ index 9ab389564c..9b7c044c81 100644
128127+ if (hashContent != null) {
129128+ for (char c : hashContent) {
130129+ byte b = (byte) in.read();
131- +
132130+ if (b != c) {
133131+ IOException toThrow = new IOException("Hash validation failed!");
134132+ try {
@@ -146,15 +144,21 @@ index 9ab389564c..9b7c044c81 100644
146144 connectionObject.getRunningFuture().get();
147145 } catch (IOException | InterruptedException | ExecutionException ex) {
148146diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ConnectionSpecTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ConnectionSpecTest.java
149- index 1035cf9bc8..55c0488d03 100644
147+ index f538c953f6..728228c63c 100644
150148--- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ConnectionSpecTest.java
151149+++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/ConnectionSpecTest.java
152- @@ -118,7 +118,7 @@ public class ConnectionSpecTest {
150+ @@ -118,10 +118,12 @@ public class ConnectionSpecTest {
153151 ByteArrayInputStream in = new ByteArrayInputStream(bytes);
154152 ByteArrayOutputStream os = new ByteArrayOutputStream();
155153 conn.prepare("Pipe server", in, os, new LspSession(), ConnectionSpecTest::setCopy, ConnectionSpecTest::copy);
156154- String reply = os.toString("UTF-8");
157155+ String reply = os.toString("UTF-8").replaceAll("\n$", "");
158156 String exp = "Pipe server listening at port ";
159157 assertTrue(reply, reply.startsWith(exp));
160- int port = Integer.parseInt(reply.substring(exp.length()));
158+ - int port = Integer.parseInt(reply.substring(exp.length(), reply.indexOf('\n', exp.length())));
159+ + int nextLineIdx = reply.indexOf('\n', exp.length());
160+ + if (nextLineIdx < 0) nextLineIdx = reply.length();
161+ + int port = Integer.parseInt(reply.substring(exp.length(), nextLineIdx));
162+ assertTrue("port is specified: " + port, port >= 1024);
163+ try (ConnectionSpec second = ConnectionSpec.parse("connect:" + port)) {
164+ second.prepare("Pipe client", in, os, new LspSession(), ConnectionSpecTest::setCopy, ConnectionSpecTest::copy);
0 commit comments