RFR: 8263364: sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java wedged in getInputStream
    Daniel Fuchs 
    dfuchs at openjdk.java.net
       
    Fri Jun 11 11:06:51 UTC 2021
    
    
  
On Fri, 11 Jun 2021 10:46:32 GMT, Ivan Šipka <isipka at openjdk.org> wrote:
> @dfuch  could you please review, thank you.
Globally looks good - still need some cleanup to make sure everything gets closed in the end.
test/jdk/sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java line 56:
> 54: 
> 55:                 ByteArrayOutputStream clientBytes;
> 56:                 Socket socket = null;
socket should probably be a volatile field in XServer si that it can be closed at the end of main()
test/jdk/sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java line 118:
> 116: 
> 117:         try {
> 118:             XServer server = new XServer(serversocket);
You should take that statement outside of the try block
test/jdk/sun/net/www/http/KeepAliveStream/KeepAliveStreamCloseWithWrongContentLength.java line 142:
> 140:         } catch (NullPointerException e) {
> 141:             throw new RuntimeException (e);
> 142:         } finally {
The finally block should also do:
var socket = server.socket;
if (socket != null) socket.close();
Or better add a close() method on XServer that would both close socket and serverSocket - and make XServer AutoCloseable so that you can transform your try { } finally {} into a try-with-resource.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4472
    
    
More information about the net-dev
mailing list