RFR: 8326568: jdk/test/com/sun/net/httpserver/bugs/B6431193.java should use try-with-resource and try-finally
Daniel Fuchs
dfuchs at openjdk.org
Wed Mar 27 15:20:22 UTC 2024
On Wed, 27 Mar 2024 14:58:48 GMT, Darragh Clarke <dclarke at openjdk.org> wrote:
> Currently this test occasionally doesn't cleanup between runs, sometimes not stopping the server or leaving Streams open
>
> Changes:
> - Use try-with-resources to ensure streams close.
> - Use try-finally to make sure the server stops before the test exits.
>
> I ran tiers 1-3 and ran this specific test on repeat and everything seems stable after the changes
Changes requested by dfuchs (Reviewer).
test/jdk/com/sun/net/httpserver/bugs/B6431193.java line 60:
> 58: t.sendResponseHeaders(200, response.length());
> 59: os.write(response.getBytes());
> 60: os.close();
no need to call `os.close()` here since it will be called by the `try ( ) { }` block.
test/jdk/com/sun/net/httpserver/bugs/B6431193.java line 61:
> 59: os.write(response.getBytes());
> 60: os.close();
> 61: error = Thread.currentThread().isDaemon();
This `error = ...` should be moved out of the `try () {` block, in a `} finally {` block to make sure the boolean is always set.
test/jdk/com/sun/net/httpserver/bugs/B6431193.java line 81:
> 79: .toURL();
> 80: InputStream is = url.openConnection(Proxy.NO_PROXY).getInputStream();
> 81: read(is);
should use try-with-resource here too. `read(is)` no longer closes `is`.
-------------
PR Review: https://git.openjdk.org/jdk/pull/18514#pullrequestreview-1963651495
PR Review Comment: https://git.openjdk.org/jdk/pull/18514#discussion_r1541313546
PR Review Comment: https://git.openjdk.org/jdk/pull/18514#discussion_r1541314366
PR Review Comment: https://git.openjdk.org/jdk/pull/18514#discussion_r1541317817
More information about the net-dev
mailing list