Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2017-02-09 23:00:35 +0000
committerStephan Herrmann2017-04-04 13:56:38 +0000
commitf77df400e3009bbbdecb497b75bcd116844d089e (patch)
tree3a5e64ed57b366c6867113aa09afa3be8bbc99d0
parent6440a95d11c2ec54750dac953cf4729c7ad71178 (diff)
downloadeclipse.jdt.core-f77df400e3009bbbdecb497b75bcd116844d089e.tar.gz
eclipse.jdt.core-f77df400e3009bbbdecb497b75bcd116844d089e.tar.xz
eclipse.jdt.core-f77df400e3009bbbdecb497b75bcd116844d089e.zip
Bug 422220: VerifyTests that use Util#getFreePort() occasionally fail
with "Address already in use at java.net.PlainSocketImpl.socketBind" Change-Id: I58189f92b1d748ba75738891e2106060de689d04 Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/EvalTestsTarget.zipbin12415 -> 13232 bytes
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationSetup.java219
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationSetup.java72
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleTest.java100
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/IDEInterface.java6
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetInterface.java9
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java107
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java7
8 files changed, 266 insertions, 254 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/EvalTestsTarget.zip b/org.eclipse.jdt.core.tests.compiler/src/EvalTestsTarget.zip
index 19bb2e9adb..804cba6db9 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/EvalTestsTarget.zip
+++ b/org.eclipse.jdt.core.tests.compiler/src/EvalTestsTarget.zip
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationSetup.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationSetup.java
index ce13db08eb..c0bfbfb973 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationSetup.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationSetup.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,6 +12,7 @@ package org.eclipse.jdt.core.tests.eval;
import java.io.IOException;
import java.io.InputStream;
+import java.net.ServerSocket;
import java.util.List;
import java.util.Map;
@@ -40,124 +41,128 @@ public class DebugEvaluationSetup extends EvaluationSetup {
protected void setUp() {
if (this.context == null) {
// Launch VM in evaluation mode
- int debugPort = Util.getFreePort();
- int evalPort = Util.getFreePort();
- LocalVMLauncher launcher;
- try {
- launcher = LocalVMLauncher.getLauncher();
- launcher.setVMArguments(new String[]{"-verify"});
- launcher.setVMPath(JRE_PATH);
- launcher.setEvalPort(evalPort);
- launcher.setEvalTargetPath(EVAL_DIRECTORY);
- launcher.setDebugPort(debugPort);
- this.launchedVM = launcher.launch();
- } catch (TargetException e) {
- throw new Error(e.getMessage());
- }
-
- // Thread that read the stout of the VM so that the VM doesn't block
- try {
- startReader("VM's stdout reader", this.launchedVM.getInputStream(), System.out);
- } catch (TargetException e) {
- }
-
- // Thread that read the sterr of the VM so that the VM doesn't block
- try {
- startReader("VM's sterr reader", this.launchedVM.getErrorStream(), System.err);
- } catch (TargetException e) {
- }
-
- // Start JDI connection (try 10 times)
- for (int i = 0; i < 10; i++) {
+ try (ServerSocket evalServer = new ServerSocket(0)) {
+ int debugPort = Util.getFreePort();
+ int evalPort = evalServer.getLocalPort();
+ LocalVMLauncher launcher;
try {
- VirtualMachineManager manager = org.eclipse.jdi.Bootstrap.virtualMachineManager();
- List connectors = manager.attachingConnectors();
- if (connectors.size() == 0)
- break;
- AttachingConnector connector = (AttachingConnector)connectors.get(0);
- Map args = connector.defaultArguments();
- Connector.Argument argument = (Connector.Argument)args.get("port");
- if (argument != null) {
- argument.setValue(String.valueOf(debugPort));
- }
- argument = (Connector.Argument)args.get("hostname");
- if (argument != null) {
- argument.setValue(launcher.getTargetAddress());
- }
- argument = (Connector.Argument)args.get("timeout");
- if (argument != null) {
- argument.setValue("10000");
- }
- this.vm = connector.attach(args);
-
- // workaround pb with some VMs
- this.vm.resume();
-
- break;
- } catch (IllegalConnectorArgumentsException e) {
- e.printStackTrace();
- try {
- System.out.println("Could not contact the VM at " + launcher.getTargetAddress() + ":" + debugPort + ". Retrying...");
- Thread.sleep(100);
- } catch (InterruptedException e2) {
- }
- } catch (IOException e) {
- e.printStackTrace();
- try {
- System.out.println("Could not contact the VM at " + launcher.getTargetAddress() + ":" + debugPort + ". Retrying...");
- Thread.sleep(100);
- } catch (InterruptedException e2) {
- }
+ launcher = LocalVMLauncher.getLauncher();
+ launcher.setVMArguments(new String[]{"-verify"});
+ launcher.setVMPath(JRE_PATH);
+ launcher.setEvalPort(evalPort);
+ launcher.setEvalTargetPath(EVAL_DIRECTORY);
+ launcher.setDebugPort(debugPort);
+ this.launchedVM = launcher.launch();
+ } catch (TargetException e) {
+ throw new Error(e.getMessage());
}
- }
- if (this.vm == null) {
- if (this.launchedVM != null) {
- // If the VM is not running, output error stream
+
+ // Thread that read the stout of the VM so that the VM doesn't block
+ try {
+ startReader("VM's stdout reader", this.launchedVM.getInputStream(), System.out);
+ } catch (TargetException e) {
+ }
+
+ // Thread that read the sterr of the VM so that the VM doesn't block
+ try {
+ startReader("VM's sterr reader", this.launchedVM.getErrorStream(), System.err);
+ } catch (TargetException e) {
+ }
+
+ // Start JDI connection (try 10 times)
+ for (int i = 0; i < 10; i++) {
try {
- if (!this.launchedVM.isRunning()) {
- InputStream in = this.launchedVM.getErrorStream();
- int read;
- do {
- read = in.read();
- if (read != -1)
- System.out.print((char)read);
- } while (read != -1);
+ VirtualMachineManager manager = org.eclipse.jdi.Bootstrap.virtualMachineManager();
+ List connectors = manager.attachingConnectors();
+ if (connectors.size() == 0)
+ break;
+ AttachingConnector connector = (AttachingConnector)connectors.get(0);
+ Map args = connector.defaultArguments();
+ Connector.Argument argument = (Connector.Argument)args.get("port");
+ if (argument != null) {
+ argument.setValue(String.valueOf(debugPort));
+ }
+ argument = (Connector.Argument)args.get("hostname");
+ if (argument != null) {
+ argument.setValue(launcher.getTargetAddress());
+ }
+ argument = (Connector.Argument)args.get("timeout");
+ if (argument != null) {
+ argument.setValue("10000");
+ }
+ this.vm = connector.attach(args);
+
+ // workaround pb with some VMs
+ this.vm.resume();
+
+ break;
+ } catch (IllegalConnectorArgumentsException e) {
+ e.printStackTrace();
+ try {
+ System.out.println("Could not contact the VM at " + launcher.getTargetAddress() + ":" + debugPort + ". Retrying...");
+ Thread.sleep(100);
+ } catch (InterruptedException e2) {
}
- } catch (TargetException e) {
} catch (IOException e) {
- }
-
- // Shut it down
- try {
- if (this.target != null) {
- this.target.disconnect(); // Close the socket first so that the OS resource has a chance to be freed.
+ e.printStackTrace();
+ try {
+ System.out.println("Could not contact the VM at " + launcher.getTargetAddress() + ":" + debugPort + ". Retrying...");
+ Thread.sleep(100);
+ } catch (InterruptedException e2) {
}
- int retry = 0;
- while (this.launchedVM.isRunning() && (++retry < 20)) {
- try {
- Thread.sleep(retry * 100);
- } catch (InterruptedException e) {
+ }
+ }
+ if (this.vm == null) {
+ if (this.launchedVM != null) {
+ // If the VM is not running, output error stream
+ try {
+ if (!this.launchedVM.isRunning()) {
+ InputStream in = this.launchedVM.getErrorStream();
+ int read;
+ do {
+ read = in.read();
+ if (read != -1)
+ System.out.print((char)read);
+ } while (read != -1);
}
+ } catch (TargetException e) {
+ } catch (IOException e) {
}
- if (this.launchedVM.isRunning()) {
- this.launchedVM.shutDown();
+
+ // Shut it down
+ try {
+ if (this.target != null) {
+ this.target.disconnect(); // Close the socket first so that the OS resource has a chance to be freed.
+ }
+ int retry = 0;
+ while (this.launchedVM.isRunning() && (++retry < 20)) {
+ try {
+ Thread.sleep(retry * 100);
+ } catch (InterruptedException e) {
+ }
+ }
+ if (this.launchedVM.isRunning()) {
+ this.launchedVM.shutDown();
+ }
+ } catch (TargetException e) {
}
- } catch (TargetException e) {
}
+ System.err.println("Could not contact the VM");
+ return;
}
- System.err.println("Could not contact the VM");
- return;
+
+ // Create context
+ this.context = new EvaluationContext();
+
+ // Create target
+ this.target = new TargetInterface();
+ this.target.connect(evalServer, 30000); // allow 30s max to connect (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=188127)
+
+ // Create name environment
+ this.env = new FileSystem(Util.getJavaClassLibs(), new String[0], null);
+ } catch (IOException e1) {
+ throw new Error("Failed to open socket", e1);
}
-
- // Create context
- this.context = new EvaluationContext();
-
- // Create target
- this.target = new TargetInterface();
- this.target.connect("localhost", evalPort, 30000); // allow 30s max to connect (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=188127)
-
- // Create name environment
- this.env = new FileSystem(Util.getJavaClassLibs(), new String[0], null);
}
super.setUp();
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationSetup.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationSetup.java
index 69665ba33c..12882d6572 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationSetup.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationSetup.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,8 +11,10 @@
package org.eclipse.jdt.core.tests.eval;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
+import java.net.ServerSocket;
import org.eclipse.jdt.core.tests.runtime.LocalVirtualMachine;
@@ -41,39 +43,43 @@ public class EvaluationSetup extends CompilerTestSetup {
protected void setUp() {
if (this.context == null) { // non null if called from subclass
- // Launch VM in evaluation mode
- int evalPort = Util.getFreePort();
- try {
- LocalVMLauncher launcher = LocalVMLauncher.getLauncher();
- launcher.setVMPath(JRE_PATH);
- launcher.setEvalPort(evalPort);
- launcher.setEvalTargetPath(EVAL_DIRECTORY);
- this.launchedVM = launcher.launch();
- } catch (TargetException e) {
- throw new Error(e.getMessage());
- }
-
- // Thread that read the stout of the VM so that the VM doesn't block
- try {
- startReader("VM's stdout reader", this.launchedVM.getInputStream(), System.out);
- } catch (TargetException e) {
- }
-
- // Thread that read the sterr of the VM so that the VM doesn't block
- try {
- startReader("VM's sterr reader", this.launchedVM.getErrorStream(), System.err);
- } catch (TargetException e) {
+ try (ServerSocket server = new ServerSocket(0)) {
+ // Launch VM in evaluation mode
+ int evalPort = server.getLocalPort();
+ try {
+ LocalVMLauncher launcher = LocalVMLauncher.getLauncher();
+ launcher.setVMPath(JRE_PATH);
+ launcher.setEvalPort(evalPort);
+ launcher.setEvalTargetPath(EVAL_DIRECTORY);
+ this.launchedVM = launcher.launch();
+ } catch (TargetException e) {
+ throw new Error(e.getMessage());
+ }
+
+ // Thread that read the stout of the VM so that the VM doesn't block
+ try {
+ startReader("VM's stdout reader", this.launchedVM.getInputStream(), System.out);
+ } catch (TargetException e) {
+ }
+
+ // Thread that read the sterr of the VM so that the VM doesn't block
+ try {
+ startReader("VM's sterr reader", this.launchedVM.getErrorStream(), System.err);
+ } catch (TargetException e) {
+ }
+
+ // Create context
+ this.context = new EvaluationContext();
+
+ // Create target
+ this.target = new TargetInterface();
+ this.target.connect(server, 30000); // allow 30s max to connect (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=188127)
+
+ // Create name environment
+ this.env = new FileSystem(Util.getJavaClassLibs(), new String[0], null);
+ } catch (IOException e1) {
+ throw new Error("Failed to open socket", e1);
}
-
- // Create context
- this.context = new EvaluationContext();
-
- // Create target
- this.target = new TargetInterface();
- this.target.connect("localhost", evalPort, 30000); // allow 30s max to connect (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=188127)
-
- // Create name environment
- this.env = new FileSystem(Util.getJavaClassLibs(), new String[0], null);
}
super.setUp();
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleTest.java
index 8019e42e66..8763eb180f 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,6 +11,8 @@
package org.eclipse.jdt.core.tests.eval;
import java.io.File;
+import java.io.IOException;
+import java.net.ServerSocket;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.tests.runtime.LocalVMLauncher;
@@ -239,58 +241,62 @@ protected IProblemFactory getProblemFactory() {
return new DefaultProblemFactory(java.util.Locale.getDefault());
}
protected void startEvaluationContext() throws TargetException {
- LocalVMLauncher launcher = LocalVMLauncher.getLauncher();
- launcher.setVMPath(JRE_PATH);
- launcher.setClassPath(RUNTIME_CLASSPATH);
- int evalPort = Util.getFreePort();
- launcher.setEvalPort(evalPort);
- launcher.setEvalTargetPath(TARGET_PATH);
- this.launchedVM = launcher.launch();
-
- (new Thread() {
- public void run() {
- try {
- java.io.InputStream in = SimpleTest.this.launchedVM.getInputStream();
- int read = 0;
- while (read != -1) {
- try {
- read = in.read();
- } catch (java.io.IOException e) {
- read = -1;
- }
- if (read != -1) {
- System.out.print((char)read);
+ try (ServerSocket server = new ServerSocket(0)) {
+ LocalVMLauncher launcher = LocalVMLauncher.getLauncher();
+ launcher.setVMPath(JRE_PATH);
+ launcher.setClassPath(RUNTIME_CLASSPATH);
+ int evalPort = server.getLocalPort();
+ launcher.setEvalPort(evalPort);
+ launcher.setEvalTargetPath(TARGET_PATH);
+ this.launchedVM = launcher.launch();
+
+ (new Thread() {
+ public void run() {
+ try {
+ java.io.InputStream in = SimpleTest.this.launchedVM.getInputStream();
+ int read = 0;
+ while (read != -1) {
+ try {
+ read = in.read();
+ } catch (java.io.IOException e) {
+ read = -1;
+ }
+ if (read != -1) {
+ System.out.print((char)read);
+ }
}
+ } catch (TargetException e) {
}
- } catch (TargetException e) {
}
- }
- }).start();
-
- (new Thread() {
- public void run() {
- try {
- java.io.InputStream in = SimpleTest.this.launchedVM.getErrorStream();
- int read = 0;
- while (read != -1) {
- try {
- read = in.read();
- } catch (java.io.IOException e) {
- read = -1;
- }
- if (read != -1) {
- System.out.print((char)read);
+ }).start();
+
+ (new Thread() {
+ public void run() {
+ try {
+ java.io.InputStream in = SimpleTest.this.launchedVM.getErrorStream();
+ int read = 0;
+ while (read != -1) {
+ try {
+ read = in.read();
+ } catch (java.io.IOException e) {
+ read = -1;
+ }
+ if (read != -1) {
+ System.out.print((char)read);
+ }
}
+ } catch (TargetException e) {
}
- } catch (TargetException e) {
}
- }
- }).start();
-
- this.requestor = new Requestor();
- this.target = new TargetInterface();
- this.target.connect("localhost", evalPort, 30000); // allow 30s max to connect (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=188127)
- this.context = new EvaluationContext();
+ }).start();
+
+ this.requestor = new Requestor();
+ this.target = new TargetInterface();
+ this.target.connect(server, 30000); // allow 30s max to connect (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=188127)
+ this.context = new EvaluationContext();
+ } catch (IOException e) {
+ throw new Error("Failed to open socket", e);
+ }
}
protected void stopEvaluationContext() {
try {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/IDEInterface.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/IDEInterface.java
index d91a9a9d78..dac44cfdb9 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/IDEInterface.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/IDEInterface.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -58,10 +58,8 @@ IDEInterface(int portNumber) {
* @throws IOException if the connection could not be established.
*/
void connect() throws IOException {
- ServerSocket server = new ServerSocket(this.portNumber);
- this.socket = server.accept();
+ this.socket = new Socket("localhost", this.portNumber);
this.socket.setTcpNoDelay(true);
- server.close();
}
/**
* Disconnects this interface from the IDE.
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetInterface.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetInterface.java
index ec3a790dcc..3f8a69cd20 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetInterface.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetInterface.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -54,18 +54,17 @@ public class TargetInterface {
* Try as long as the given time (in ms) has not expired.
* Use isConnected() to find out if the connection was successful.
*/
-public void connect(String targetAddress, int portNumber, int timeout) {
+public void connect(ServerSocket server, int timeout) {
if (isConnected()) {
return;
}
- if (portNumber > 0) {
+ if (server != null) {
long startTime = System.currentTimeMillis();
do {
try {
- this.socket = new Socket(targetAddress, portNumber);
+ this.socket = server.accept();
this.socket.setTcpNoDelay(true);
break;
- } catch (UnknownHostException e) {
} catch (IOException e) {
}
if (this.socket == null) {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java
index de9ba93db8..8ea0fd5db3 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java
@@ -146,7 +146,7 @@ public String getExecutionError(){
private String getVerifyTestsCode() {
return
"/*******************************************************************************\n" +
- " * Copyright (c) 2000, 2011 IBM Corporation and others.\n" +
+ " * Copyright (c) 2000, 2017 IBM Corporation and others.\n" +
" * All rights reserved. This program and the accompanying materials\n" +
" * are made available under the terms of the Eclipse Public License v1.0\n" +
" * which accompanies this distribution, and is available at\n" +
@@ -166,7 +166,6 @@ private String getVerifyTestsCode() {
"import java.io.InputStream;\n" +
"import java.lang.reflect.InvocationTargetException;\n" +
"import java.lang.reflect.Method;\n" +
- "import java.net.ServerSocket;\n" +
"import java.net.Socket;\n" +
"import java.util.StringTokenizer;\n" +
"\n" +
@@ -345,10 +344,8 @@ private String getVerifyTestsCode() {
" verify.run();\n" +
"}\n" +
"public void run() throws IOException {\n" +
- " ServerSocket server = new ServerSocket(this.portNumber);\n" +
- " this.socket = server.accept();\n" +
+ " this.socket = new Socket(\"localhost\", this.portNumber);\n" +
" this.socket.setTcpNoDelay(true);\n" +
- " server.close();\n" +
"\n" +
" DataInputStream in = new DataInputStream(this.socket.getInputStream());\n" +
" final DataOutputStream out = new DataOutputStream(this.socket.getOutputStream());\n" +
@@ -496,62 +493,66 @@ private void launchVerifyTestsIfNeeded(String[] classpaths, String[] vmArguments
launcher.setVMArguments(new String[] {"-verify"});
}
launcher.setProgramClass(VerifyTests.class.getName());
- int portNumber = Util.getFreePort();
- launcher.setProgramArguments(new String[] {Integer.toString(portNumber)});
- try {
- this.vm = launcher.launch();
- final InputStream input = this.vm.getInputStream();
- Thread outputThread = new Thread(new Runnable() {
- public void run() {
- try {
- int c = input.read();
- while (c != -1) {
- TestVerifier.this.outputBuffer.append((char) c);
- c = input.read();
+ try (ServerSocket server = new ServerSocket(0)) {
+ int portNumber = server.getLocalPort();
+
+ launcher.setProgramArguments(new String[] {Integer.toString(portNumber)});
+ try {
+ this.vm = launcher.launch();
+ final InputStream input = this.vm.getInputStream();
+ Thread outputThread = new Thread(new Runnable() {
+ public void run() {
+ try {
+ int c = input.read();
+ while (c != -1) {
+ TestVerifier.this.outputBuffer.append((char) c);
+ c = input.read();
+ }
+ } catch(IOException ioEx) {
+ }
+ }
+ });
+ final InputStream errorStream = this.vm.getErrorStream();
+ Thread errorThread = new Thread(new Runnable() {
+ public void run() {
+ try {
+ int c = errorStream.read();
+ while (c != -1) {
+ TestVerifier.this.errorBuffer.append((char) c);
+ c = errorStream.read();
+ }
+ } catch(IOException ioEx) {
}
- } catch(IOException ioEx) {
}
+ });
+ outputThread.start();
+ errorThread.start();
+ } catch(TargetException e) {
+ throw new Error(e.getMessage());
+ }
+
+ // connect to the vm
+ this.socket = null;
+ boolean isVMRunning = false;
+ do {
+ try {
+ this.socket = server.accept();
+ this.socket.setTcpNoDelay(true);
+ break;
+ } catch (UnknownHostException e) {
+ } catch (IOException e) {
}
- });
- final InputStream errorStream = this.vm.getErrorStream();
- Thread errorThread = new Thread(new Runnable() {
- public void run() {
+ if (this.socket == null) {
try {
- int c = errorStream.read();
- while (c != -1) {
- TestVerifier.this.errorBuffer.append((char) c);
- c = errorStream.read();
- }
- } catch(IOException ioEx) {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
}
+ isVMRunning = this.vm.isRunning();
}
- });
- outputThread.start();
- errorThread.start();
- } catch(TargetException e) {
+ } while (this.socket == null && isVMRunning);
+ } catch (IOException e) {
throw new Error(e.getMessage());
}
-
- // connect to the vm
- this.socket = null;
- boolean isVMRunning = false;
- do {
- try {
- this.socket = new Socket("localhost", portNumber);
- this.socket.setTcpNoDelay(true);
- break;
- } catch (UnknownHostException e) {
- } catch (IOException e) {
- }
- if (this.socket == null) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- isVMRunning = this.vm.isRunning();
- }
- } while (this.socket == null && isVMRunning);
-
}
/**
* Loads and runs the given class.
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java
index 0fc1cf78c8..4adc9ae724 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,7 +19,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.net.ServerSocket;
import java.net.Socket;
import java.util.StringTokenizer;
@@ -199,10 +198,8 @@ public static void main(String[] args) throws IOException {
verify.run();
}
public void run() throws IOException {
- ServerSocket server = new ServerSocket(this.portNumber);
- this.socket = server.accept();
+ this.socket = new Socket("localhost", this.portNumber);
this.socket.setTcpNoDelay(true);
- server.close();
DataInputStream in = new DataInputStream(this.socket.getInputStream());
final DataOutputStream out = new DataOutputStream(this.socket.getOutputStream());

Back to the top