This test has been failing intermittently since I updated it recently to cover another similar issue. The test shares a ServerSocket instance across two threads, and as such it should be a volatile field. The test should also ensure that any thread that it starts completes before it continues its iteration.
With these simple changes I ran the test several thousand times, on a machine that reproduced the intermittent failure 1 in 10 times, and it was never seen to fail. diff --git a/test/sun/net/www/http/HttpClient/StreamingRetry.java b/test/sun/net/www/http/HttpClient/StreamingRetry.java --- a/test/sun/net/www/http/HttpClient/StreamingRetry.java +++ b/test/sun/net/www/http/HttpClient/StreamingRetry.java @@ -37,13 +37,13 @@ public class StreamingRetry implements Runnable { static final int ACCEPT_TIMEOUT = 20 * 1000; // 20 seconds - ServerSocket ss; + volatile ServerSocket ss; - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws Exception { (new StreamingRetry()).instanceMain(); } - void instanceMain() throws IOException { + void instanceMain() throws Exception { out.println("Test with default method"); test(null); out.println("Test with POST method"); @@ -54,12 +54,13 @@ if (failed > 0) throw new RuntimeException("Some tests failed"); } - void test(String method) throws IOException { + void test(String method) throws Exception { ss = new ServerSocket(0); ss.setSoTimeout(ACCEPT_TIMEOUT); int port = ss.getLocalPort(); - (new Thread(this)).start(); + Thread otherThread = new Thread(this); + otherThread.start(); try { URL url = new URL("http://localhost:" + port + "/"); @@ -77,6 +78,7 @@ //expected.printStackTrace(); } finally { ss.close(); + otherThread.join(); } } -Chris.