8130657: com/sun/net/httpserver/Test5.java failed with java.lang.RuntimeException: wrong string result
8085575: java/net/Socket/InheritHandle.java fails intermittently with "Address already in use"
Reviewed-by: dfuchs
--- a/jdk/test/com/sun/net/httpserver/Test5.java Mon Sep 26 14:56:35 2016 +0200
+++ b/jdk/test/com/sun/net/httpserver/Test5.java Mon Sep 26 08:19:07 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -145,6 +145,7 @@
socket.close();
s = new String (b,0,count, "ISO8859_1");
if (!compare (s, result)) {
+ System.err.println(" Expected [" + result + "]\n actual [" + s + "]");
throw new RuntimeException ("wrong string result");
}
}
--- a/jdk/test/java/net/MulticastSocket/TimeToLive.java Mon Sep 26 14:56:35 2016 +0200
+++ b/jdk/test/java/net/MulticastSocket/TimeToLive.java Mon Sep 26 08:19:07 2016 -0700
@@ -37,26 +37,27 @@
static int[] bad_ttls = { -1, 256 };
public static void main(String[] args) throws Exception {
- MulticastSocket socket = new MulticastSocket();
- int ttl = socket.getTimeToLive();
- System.out.println("default ttl: " + ttl);
- for (int i = 0; i < new_ttls.length; i++) {
- socket.setTimeToLive(new_ttls[i]);
- if (!(new_ttls[i] == socket.getTimeToLive())) {
- throw new RuntimeException("test failure, set/get differ: " +
- new_ttls[i] + " / " +
- socket.getTimeToLive());
+ try (MulticastSocket socket = new MulticastSocket()) {
+ int ttl = socket.getTimeToLive();
+ System.out.println("default ttl: " + ttl);
+ for (int i = 0; i < new_ttls.length; i++) {
+ socket.setTimeToLive(new_ttls[i]);
+ if (!(new_ttls[i] == socket.getTimeToLive())) {
+ throw new RuntimeException("test failure, set/get differ: " +
+ new_ttls[i] + " / " +
+ socket.getTimeToLive());
+ }
}
- }
- for (int j = 0; j < bad_ttls.length; j++) {
- boolean exception = false;
- try {
- socket.setTimeToLive(bad_ttls[j]);
- } catch (IllegalArgumentException e) {
- exception = true;
- }
- if (!exception) {
- throw new RuntimeException("bad argument accepted: " + bad_ttls[j]);
+ for (int j = 0; j < bad_ttls.length; j++) {
+ boolean exception = false;
+ try {
+ socket.setTimeToLive(bad_ttls[j]);
+ } catch (IllegalArgumentException e) {
+ exception = true;
+ }
+ if (!exception) {
+ throw new RuntimeException("bad argument accepted: " + bad_ttls[j]);
+ }
}
}
}
--- a/jdk/test/java/net/Socket/InheritHandle.java Mon Sep 26 14:56:35 2016 +0200
+++ b/jdk/test/java/net/Socket/InheritHandle.java Mon Sep 26 08:19:07 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
@author Chris Hegarty
*/
+import java.net.BindException;
import java.net.ServerSocket;
import java.io.File;
import java.io.IOException;
@@ -74,6 +75,11 @@
} catch (IOException ioe) {
System.out.println("Cannot create process");
ioe.printStackTrace();
+ try {
+ ss.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
return;
}
@@ -85,9 +91,18 @@
System.out.println("Now close the socket and try to create another" +
" one listening on the same port");
ss.close();
- ss = new ServerSocket(port);
- System.out.println("Second ServerSocket created successfully");
- ss.close();
+ int retries = 0;
+ while (retries < 5) {
+ try (ServerSocket s = new ServerSocket(port);) {
+ System.out.println("Second ServerSocket created successfully");
+ break;
+ } catch (BindException e) {
+ System.out.println("BindException \"" + e.getMessage() + "\", retrying...");
+ Thread.sleep(100L);
+ retries ++;
+ continue;
+ }
+ }
} catch (InterruptedException ie) {
} catch (IOException ioe) {