test/jdk/sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 4533243 |
26 * @bug 4533243 |
27 * @summary Closing a keep alive stream gives NullPointerException |
27 * @summary Closing a keep alive stream gives NullPointerException |
|
28 * @library /test/lib |
28 * @run main/othervm/timeout=30 KeepAliveStreamCloseWithWrongContentLength |
29 * @run main/othervm/timeout=30 KeepAliveStreamCloseWithWrongContentLength |
29 */ |
30 */ |
30 |
31 |
31 import java.net.*; |
32 import java.net.*; |
32 import java.io.*; |
33 import java.io.*; |
|
34 import jdk.test.lib.net.URIBuilder; |
33 |
35 |
34 public class KeepAliveStreamCloseWithWrongContentLength { |
36 public class KeepAliveStreamCloseWithWrongContentLength { |
35 |
37 |
36 static class XServer extends Thread { |
38 static class XServer extends Thread { |
37 ServerSocket srv; |
39 ServerSocket srv; |
73 } |
75 } |
74 } |
76 } |
75 } |
77 } |
76 |
78 |
77 public static void main (String[] args) throws Exception { |
79 public static void main (String[] args) throws Exception { |
78 ServerSocket serversocket = new ServerSocket (0); |
80 final InetAddress loopback = InetAddress.getLoopbackAddress(); |
|
81 final ServerSocket serversocket = new ServerSocket(); |
|
82 serversocket.bind(new InetSocketAddress(loopback, 0)); |
|
83 |
79 try { |
84 try { |
80 int port = serversocket.getLocalPort (); |
85 int port = serversocket.getLocalPort (); |
81 XServer server = new XServer (serversocket); |
86 XServer server = new XServer (serversocket); |
82 server.start (); |
87 server.start (); |
83 URL url = new URL ("http://localhost:"+port); |
88 URL url = URIBuilder.newBuilder() |
84 HttpURLConnection urlc = (HttpURLConnection)url.openConnection (); |
89 .scheme("http") |
|
90 .loopback() |
|
91 .port(port) |
|
92 .toURL(); |
|
93 HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY); |
85 InputStream is = urlc.getInputStream (); |
94 InputStream is = urlc.getInputStream (); |
86 int c = 0; |
95 int c = 0; |
87 while (c != -1) { |
96 while (c != -1) { |
88 try { |
97 try { |
89 c=is.read(); |
98 c=is.read(); |
96 } catch (IOException e) { |
105 } catch (IOException e) { |
97 return; |
106 return; |
98 } catch (NullPointerException e) { |
107 } catch (NullPointerException e) { |
99 throw new RuntimeException (e); |
108 throw new RuntimeException (e); |
100 } finally { |
109 } finally { |
101 if (serversocket != null) serversocket.close(); |
110 serversocket.close(); |
102 } |
111 } |
103 } |
112 } |
104 } |
113 } |