test/com/sun/jdi/NoLaunchOptionTest.java

Print this page

        

@@ -29,10 +29,13 @@
  *
  *  @run compile -g NoLaunchOptionTest.java
  *  @build VMConnection
  *  @run main/othervm NoLaunchOptionTest
  */
+
+import java.net.ServerSocket;
+
 public class NoLaunchOptionTest extends Object {
     private Process subprocess;
     private int subprocessStatus;
     private static final String CR = System.getProperty("line.separator");
     private static final int BUFFERSIZE = 4096;

@@ -119,16 +122,23 @@
 
         return result;
     }
 
     public static void main(String[] args) throws Exception {
+        // find a free port
+        ServerSocket ss = new ServerSocket(0);
+        int port = ss.getLocalPort();
+        ss.close();
+        String address = String.valueOf(port);
+
         String javaExe = System.getProperty("java.home") +
             java.io.File.separator + "bin" +
             java.io.File.separator + "java";
         String targetClass = "NotAClass";
         String cmds [] = {javaExe,
-                          "-agentlib:jdwp=transport=dt_socket,address=8000," +
+                          "-agentlib:jdwp=transport=dt_socket,address=" + 
+                          address + "," +
                           "onthrow=java.lang.ClassNotFoundException,suspend=n",
                           targetClass};
         NoLaunchOptionTest myTest = new NoLaunchOptionTest();
         String results [] = myTest.run(VMConnection.insertDebuggeeVMOptions(cmds));
         if ((results[RETSTAT].equals("1")) &&