提交 5329fd1d 编写于 作者: C chegar

8002297: sun/net/www/protocol/http/StackTraceTest.java fails intermittently

Reviewed-by: alanb, dsamersoff
上级 cedae79c
...@@ -32,26 +32,28 @@ import java.net.*; ...@@ -32,26 +32,28 @@ import java.net.*;
import java.io.IOException; import java.io.IOException;
public class StackTraceTest { public class StackTraceTest {
public static void main(String[] args) { public static void main(String[] args) throws Exception {
URL url;
try (ServerSocket ss = new ServerSocket(0)) { // refusing socket
url = new URL("http://localhost:" + ss.getLocalPort() + "/");
}
URLConnection uc = url.openConnection();
// Trigger implicit connection by trying to retrieve bogus
// response header, and force remembered exception
uc.getHeaderFieldKey(20);
try { try {
URL url = new URL("http://localhost:8080/"); uc.getInputStream(); // expect to throw
URLConnection uc = url.openConnection(); throw new RuntimeException("Expected getInputStream to throw");
System.out.println("key = "+uc.getHeaderFieldKey(20));
uc.getInputStream();
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); if (!(ioe instanceof ConnectException))
throw new RuntimeException("Expect ConnectException, got " + ioe);
if (!(ioe instanceof ConnectException)) { if (ioe.getMessage() == null)
throw new RuntimeException("Expect ConnectException, got "+ioe);
}
if (ioe.getMessage() == null) {
throw new RuntimeException("Exception message is null"); throw new RuntimeException("Exception message is null");
} if (ioe.getCause() == null)
throw new RuntimeException("Excepting a chained exception, but got: ",
// this exception should be a chained exception ioe);
if (ioe.getCause() == null) {
throw new RuntimeException("Excepting a chained exception, but got: ", ioe);
}
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册