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
8276970: Default charset for PrintWriter that wraps PrintStream #6401
Conversation
/csr |
👋 Welcome back naoto! A progress list of the required criteria for merging this PR into |
@naotoj this pull request will not be integrated until the CSR request JDK-8277078 for issue JDK-8276970 has been approved. |
Webrevs
|
@@ -68,6 +68,7 @@ | |||
private final boolean autoFlush; | |||
private boolean trouble = false; | |||
private Formatter formatter; | |||
private Charset charset; |
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 Naoto, should this be formally marked as final
?
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 catch! I will make it final
.
I tested some of java tool commands on #5771 .
It worked fine as expected on CentOS7 (ja_JP.eucjp locale) and Windows 10 Pro for Japanese. |
* default charset. | ||
* OutputStreamWriter, which will convert characters into bytes using | ||
* the charset in {@code out} if it is a {@code PrintStream}, or using | ||
* the default charset. | ||
* |
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 I prefer the wording in OutputStreamWriter because it puts the default encoding first and makes it just a bit clearer that the PS case is the exception.
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.
Will use OutputStreamWriter
's wording here. Also I am tempted to make PrintStream::charset()
public, as some custom OutputStreamWriter
implementations would also need the charset information.
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.
Also I am tempted to make
PrintStream::charset()
public, as some customOutputStreamWriter
implementations would also need the charset information.
I think that would be good addition.
Good to know! Thank you for your help. |
*/ | ||
public Charset charset() { | ||
return charset; | ||
} |
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 looks good. You could use {@return the charset used ...} to avoid repeating the message. Also might be better to move the method to after the constructors so that it's with the other instance methods.
The update method descriptions in PS, PW, and OutputStreamWriter look good.
So overall I think we've got to a good place. Wrapping a PS with PW and not inheriting the charset is an potential accident that goes back 20+ years.
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, Alan. Modified as suggested.
…n along with other instance methods.
BTW, I still observe on Windows (system locale=ja-JP):
This needs to be separately addressed in https://bugs.openjdk.java.net/browse/JDK-8274784 |
@naotoj 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 195 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 |
The following diff seems to fix the garbled char issue above:
|
/integrate |
Going to push as commit 231fb61.
Your commit was automatically rebased without conflicts. |
Many thanks, @naotoj . |
Fixing the default charset for PrintWriter/OutputStreamWriter that wraps a PrintStream to its charset. This issue was raised during the conversations in #5771
A corresponding CSR has also been drafted: https://bugs.openjdk.java.net/browse/JDK-8277078
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6401/head:pull/6401
$ git checkout pull/6401
Update a local copy of the PR:
$ git checkout pull/6401
$ git pull https://git.openjdk.java.net/jdk pull/6401/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 6401
View PR using the GUI difftool:
$ git pr show -t 6401
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6401.diff