--- old/test/java/rmi/testlibrary/TestLibrary.java 2012-12-05 15:56:48.288527253 -0500 +++ new/test/java/rmi/testlibrary/TestLibrary.java 2012-12-05 15:56:48.124530576 -0500 @@ -54,6 +54,7 @@ import java.rmi.server.UnicastRemoteObject; import java.util.Enumeration; import java.util.Properties; + import sun.rmi.registry.RegistryImpl; import sun.rmi.server.UnicastServerRef; import sun.rmi.transport.Endpoint; @@ -92,6 +93,7 @@ public final static int INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT = 64003; public final static int INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT = 64004; public final static int READTEST_REGISTRY_PORT = 64005; + private final static int MAX_SERVER_SOCKET_TRIES = 10; static void mesg(Object mesg) { System.err.println("TEST_LIBRARY: " + mesg.toString()); @@ -125,33 +127,12 @@ bomb(null, e); } - /** - * Property accessors - */ - private static boolean getBoolean(String name) { - return (new Boolean(getProperty(name, "false")).booleanValue()); - } - private static Integer getInteger(String name) { - int val = 0; - Integer value = null; - - String propVal = getProperty(name, null); - if (propVal == null) { - return null; - } - - try { - value = new Integer(Integer.parseInt(propVal)); - } catch (NumberFormatException nfe) { - } - return value; - } public static String getProperty(String property, String defaultVal) { final String prop = property; final String def = defaultVal; return ((String) java.security.AccessController.doPrivileged - (new java.security.PrivilegedAction() { - public Object run() { + (new java.security.PrivilegedAction() { + public String run() { return System.getProperty(prop, def); } })); @@ -170,8 +151,8 @@ final String prop = property; final String val = value; java.security.AccessController.doPrivileged - (new java.security.PrivilegedAction() { - public Object run() { + (new java.security.PrivilegedAction() { + public Void run() { System.setProperty(prop, val); return null; } @@ -188,7 +169,7 @@ out.println("-------------------Test environment----------" + "---------"); - for(Enumeration keys = System.getProperties().keys(); + for(Enumeration keys = System.getProperties().keys(); keys.hasMoreElements();) { String property = (String) keys.nextElement(); @@ -252,7 +233,7 @@ /* * Obtain the URL for the codebase. */ - URL codebaseURL = dstDir.toURL(); + URL codebaseURL = dstDir.toURI().toURL(); /* * Specify where we will copy the class definition from, if @@ -407,26 +388,46 @@ */ public static int getUnusedRandomPort() { int numTries = 0; - int unusedRandomPort = FIXED_PORT_MIN; - Exception ex = null; + int unusedRandomPort = -1; + IOException ex = null; - while (numTries++ < 10) { + while (numTries++ < MAX_SERVER_SOCKET_TRIES) { ex = null; //reset try (ServerSocket ss = new ServerSocket(0)) { unusedRandomPort = ss.getLocalPort(); - } catch (Exception e) { + } catch (IOException e) { ex = e; + // temporarily print stack trace here until we find out why + // tests are failing. + System.err.println("TestLibrary.getUnusedRandomPort() caught " + + "exception on iteration " + numTries + + (numTries==MAX_SERVER_SOCKET_TRIES ? " (the final try)." + : ".")); + ex.printStackTrace(); } - if (!isReservedPort(unusedRandomPort)) { - return unusedRandomPort; + if (unusedRandomPort >= 0) { + if (isReservedPort(unusedRandomPort)) { + System.out.println("INFO: On try # " + numTries + + (numTries==MAX_SERVER_SOCKET_TRIES ? ", the final try, ": ",") + + " ServerSocket(0) returned the reserved port " + + unusedRandomPort + + " in TestLibrary.getUnusedRandomPort() "); + } else { + return unusedRandomPort; + } } } // If we're here, then either an exception was thrown or the port is // a reserved port. - throw new RuntimeException("Error getting unused random port.", ex); + if (ex==null) { + throw new RuntimeException("Error getting unused random port. The" + +" last port returned by ServerSocket(0) was a reserved port"); + } else { + throw new RuntimeException("Error getting unused random port.", ex); + } } /**