-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8326568: jdk/test/com/sun/net/httpserver/bugs/B6431193.java should use try-with-resource and try-finally #18514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
👋 Welcome back dclarke! A progress list of the required criteria for merging this PR into |
|
@DarraghClarke This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 164 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
@DarraghClarke The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
| error = Thread.currentThread().isDaemon(); | ||
| t.sendResponseHeaders(200, response.length()); | ||
| os.write(response.getBytes()); | ||
| os.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to call os.close() here since it will be called by the try ( ) { } block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line with os.close() should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for missing that one on the last PR, removing it now
| t.sendResponseHeaders(200, response.length()); | ||
| os.write(response.getBytes()); | ||
| os.close(); | ||
| error = Thread.currentThread().isDaemon(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error = ... should be moved out of the try () { block, in a } finally { block to make sure the boolean is always set.
| InputStream is = url.openConnection(Proxy.NO_PROXY).getInputStream(); | ||
| read (is); | ||
| server.stop(0); | ||
| read(is); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use try-with-resource here too. read(is) no longer closes is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, looking at it again would it be worthwhile to get rid of the read method and just use is.readAllBytes in it's place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends on how much data the test actually sends. If it's a small amount readAllBytes is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only data sent is this string: This is the response
| t.sendResponseHeaders(200, response.length()); | ||
| os.write(response.getBytes()); | ||
| os.close(); | ||
| error = Thread.currentThread().isDaemon(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Darragh, since we are updating this test, perhaps we should rename that variable to be a bit more precise? Looking at the history of this test, it was introduced to verify that the HTTP request was handled on the server side in a non-daemon thread. So perhaps rename that field to handlerIsDaemon? Then, the place where we assert this value, perhaps change it to:
if (handlerIsDaemon) {
throw new RuntimeException ("request was handled by a daemon thread");
}|
Thanks for the suggestions, I've implemented those changes and reran tests to make sure everything is still stable. |
| server.setExecutor(null); | ||
| // creates a default executor | ||
| server.start(); | ||
| server.start(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
server.start() (and what preceeds) should be called before entering the try block
| InputStream is = url.openConnection(Proxy.NO_PROXY).getInputStream(); | ||
| read (is); | ||
| server.stop(0); | ||
| if (error) { | ||
| throw new RuntimeException ("error in test"); | ||
| is.readAllBytes(); | ||
| is.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use try-with-resource here
| error = Thread.currentThread().isDaemon(); | ||
| t.sendResponseHeaders(200, response.length()); | ||
| os.write(response.getBytes()); | ||
| os.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line with os.close() should be removed
|
Darragh, one other thing - I haven't paid close attention to this test, so can't say for certain - are we sure that when the test code reaches the place where we assert on InputStream is = url.openConnection(Proxy.NO_PROXY).getInputStream();
read (is);is enough to guarantee that the handler was invoked. I would have looked at the test code and the HttpURLConnection implementation myself, but I need to head out now. |
That's a good point, from my testing it seems to consistently be reached but I'm not sure if it's 100% guaranteed. Would a |
|
Hello Darragh,
I ran some experiments with this test and it appears that if the handler isn't invoked then we won't reach the place where we assert the Just as an extra precaution, what you could perhaps do is initialize |
dfuch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM now.
dfuch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. LGTM now.
jaikiran
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Darragh for the updates. This now looks good to me.
|
/integrate |
|
Going to push as commit 86cb767.
Your commit was automatically rebased without conflicts. |
|
@DarraghClarke Pushed as commit 86cb767. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Currently this test occasionally doesn't cleanup between runs, sometimes not stopping the server or leaving Streams open
Changes:
I ran tiers 1-3 and ran this specific test on repeat and everything seems stable after the changes
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18514/head:pull/18514$ git checkout pull/18514Update a local copy of the PR:
$ git checkout pull/18514$ git pull https://git.openjdk.org/jdk.git pull/18514/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 18514View PR using the GUI difftool:
$ git pr show -t 18514Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18514.diff
Webrev
Link to Webrev Comment