8341566: Add Reader.of(CharSequence)#21371
Conversation
|
👋 Welcome back mkarg! A progress list of the required criteria for merging this PR into |
|
@mkarg 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 253 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. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@RogerRiggs, @jaikiran, @liach, @AlanBateman) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
Webrevs
|
|
/csr |
|
@AlanBateman has indicated that a compatibility and specification (CSR) request is needed for this pull request. @mkarg please create a CSR request for issue JDK-8341566 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
|
Reader.of(CharSequence) looks much better than introducing CharSequenceReader. It won't have an equivalent on Writer but I think that is okay. Also it means that the user will need to deal with close throwing IOException but anything using Reader has to do this already. I think it would be better to drop "API compatible with StringReader" from the method description. An apiNote in StringReader can direct readers to the static factory method. Also I think drop the "lock" field from the API docs as it's a protected field and only interesting to subclasses. The Reader class does not specify if Reader is thread-safe so the method description doesn't need to say too much. For clarify then it could just say something like "the resulting Reader is not safe for use by multiple concurrent threads. If the Reader is to be used by more than one thread it should be controlled by appropriate synchronization". The parameter name is currently "c", maybe you mean "cs"? The method will need to specify NPE for the of(null) case. |
Updated JavaDocs according to Alan Bateman's review comments: * Dropped "API compatible with StringReader" from description * @APinote in StringReader refers to static factory method * Dropped "lock" field from API docs * Added "The resulting Reader is not safe for use by multiple concurrent threads. If the Reader is to be used by more than one thread it should be controlled by appropriate synchronization" * Deviating from your proposal, I renamed parameter "c" to "source" for clarity as the name "cs" already exists as an internal variable * Method specifies NPE for `of(null)` case I addition, JavaDocs now says "reader", not "stream" anymore.
|
Thank you, Alan! I have updated the JavaDocs according to your comments:
I addition, JavaDocs now says "reader", not "stream" anymore. |
Dropping non-public JavaDocs
@AlanBateman Can you please review the CSR request so I can finish it? Thanks! |
…rts the mark and reset ... could move up to become the second paragraph.'
|
Thank you, Alan. I now have adjusted the JavaDocs to your exact proposals. Kindly requesting final reviews from everybody, so we can finally move this PR through the door. Thank you! :-) |
|
@liach Alan's latest minor edit request auto-removed your approval from this PR. Kindly asking to reapply your approval. Thanks. |
|
The javadoc text changes look fine; since this does not constitute specification changes, we don't need to re-draft our CSR to reflect the text changes. |
liach
left a comment
There was a problem hiding this comment.
The diff from Jaikiran and Roger's latest review is: 487b938...97e3144
There's no implementation change, so assuming the previous reviewers' approvals hold.
|
I do share Chen's assumption, therefore requesting integration now. /integrate |
|
Please allow us to run some internal testing to ensure there won't be intermittent test failures before anyone sponsors this patch. |
|
An issue with the simple name
... that may look like they do something different. I can't say whether we should consider this a serious issue or not, though. I don't know if it justifies a big ugly name like |
|
I think this scenario has a close analogy with java.util.Scanner constructors. Does such a fault happen to Scanner often? |
There always will be a small group this misunderstands things and does not read JavaDocs, we can never find "the perfect API" to prevent this completely. The question is if we need to make the API worse in turn and bother all others with ugly lengthy names? I personally think the actual risk here is negligible, and the solution ("RTFM") is rather simple to implement. ;-) To sum up, IMHO as soon as Chen finished the internal tests, we should close this discussion and merge this PR as-is. |
|
Thanks Markus! The java.io tests succeed with repeats and the only test failures in tier 1-3 were ones problem-listed by f7a61fc. FYI, besides Kevin's question, there was another concern about this API's interaction with BufferedReader (as you know, many Reader users wrap any Reader into a BufferedReader, especially you want to read all lines from a reader). We currently decide that we might explore line reading capability to Reader, but anyways that will not affect this patch. And I have consulted with Kevin in private; he thinks this minor confusion is fine. Sponsoring. /sponsor |
|
Going to push as commit 3c14c2b.
Your commit was automatically rebased without conflicts. |
|
I have drafted a release note for JDK-8341566 in JDK-8344910. Kindly asking for reviews! :-) |
Thanks for creating this. I've edited it so that it is now focused on highlighting the new API and nothing else. Chen had some good suggestions too. |
|
Mailing list message from Markus Karg on core-libs-dev: Thank you so much for your kind reviews, Alan and Chen! :-) I have slighly extended Alan's draft to let people better understand the differences, hence to be able to actively chose between StringReader and Reader.of(CharSequence): "The static factory method `java.io.Reader.of(CharSequence)` has been added in get a `Reader` that reads characters from a `CharSequence` (`String` and `StringBuilder` are examples of a `CharSequence`). The returned `Reader` is more efficient than using a `java.io.StringReader` in some cases, as the latter requires conversion to `String` and synchronization." Is that OK? I see the risk that people cannot make a well-founded decision without. I am not a native English speaker. Do we need to add "TO" in "...added in TO get a Reader..."? -Markus -----Urspr?ngliche Nachricht----- On Sat, 23 Nov 2024 15:08:38 GMT, Markus KARG <duke at openjdk.org> wrote:
Thanks for creating this. I've edited it so that it is now focused on highlighting the new API and nothing else. Chen had some good suggestions too. ------------- PR Comment: https://git.openjdk.org/jdk/pull/21371#issuecomment-2496042639 |
|
Mailing list message from Roger Riggs on core-libs-dev: Hi Markus, Thanks for drafting the release note and improvments. Slight update "add in get a" -> "added to get a". Regards, Roger p.s.? An Oracle Tech writer also reviews and may do minor cleanup to On 11/24/24 11:12 AM, Markus Karg wrote: |
This Pull Requests proposes an implementation for JDK-8341566: Adding the new method
public static Reader Reader.of(CharSequence)will return an anonymous, non-synchronized implementation of aReaderfor each kind ofCharSequenceimplementation. It is optimized forString,StringBuilder,StringBufferandCharBuffer.In addition, this Pull Request proposes to replace the implementation of
StringReaderto become a simple synchronized wrapper aroundReader.of(CharSequence)for the case ofStringsources. To ensure correctness, this PR...StringBuilderto become the de-facto implementation ofReader.of(), then stripped synchronized from it on the left hand, but kept just a synchronized wrapper on the right hand. Then added aswitchfor optimizations within the original code, at the exact location where previously just an optimization forStringlived in.Of.java), and applied that test upon the modifiedStringBuilder.Wherever new JavaDocs were added, existing phrases from other code locations have been copied and adapted, to best match the same wording.
Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21371/head:pull/21371$ git checkout pull/21371Update a local copy of the PR:
$ git checkout pull/21371$ git pull https://git.openjdk.org/jdk.git pull/21371/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 21371View PR using the GUI difftool:
$ git pr show -t 21371Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21371.diff
Webrev
Link to Webrev Comment