Skip to content
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

8353698: Output of Simple Web Server is garbled if the console's encoding is not UTF-8 #24437

Closed
wants to merge 4 commits into from

Conversation

tabata-d
Copy link
Contributor

@tabata-d tabata-d commented Apr 4, 2025

The output jwebserver and java -m jdk.httpserver uses UTF-8 encoding. Therefore, if the console encoding is not set to UTF-8 (for example, MS932 on Japanese Windows), garbled characters may appear. 
Since System.out knows the console's encoding, there's no need to specify it again with PrintWriter constructor.

The output jwebserver and java -m jdk.httpserver is localized in Japanese, German, and Chinese. This bug only occurs in these localized languages, so I haven't added any tests.
I have confirmed that the output of the two commands is not garbled in the default command prompts of both Japanese Windows and English Windows.

I tested jdk/com/sun/net/httpserver/simpleserver on English Windows, and all tests passed. However, when running on Japanese Windows, some tests failed because they expected output only in English.
I modified the tests so that jwebserver and java -m jdk.httpserver within the tests are executed with an English locale. After this modification, all tests passed on Japanese Windows.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8353698: Output of Simple Web Server is garbled if the console's encoding is not UTF-8 (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24437/head:pull/24437
$ git checkout pull/24437

Update a local copy of the PR:
$ git checkout pull/24437
$ git pull https://git.openjdk.org/jdk.git pull/24437/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24437

View PR using the GUI difftool:
$ git pr show -t 24437

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24437.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 4, 2025

👋 Welcome back tabata-d! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Apr 4, 2025

@tabata-d 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:

8353698: Output of Simple Web Server is garbled if the console's encoding is not UTF-8

Reviewed-by: djelinski, dfuchs

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 94 new commits pushed to the master branch:

  • 60fbf73: 8353709: Debug symbols bundle should contain full debug files when building --with-external-symbols-in-bundles=public
  • 77fff61: 8341095: Possible overflow in os::Posix::print_uptime_info
  • 9128ec6: 8352935: Launcher should not add $JDK/../lib to LD_LIBRARY_PATH
  • 27c8d9d: 8352686: Opensource JInternalFrame tests - series3
  • 66435c2: 8352684: Opensource JInternalFrame tests - series1
  • 353e173: 8219408: Tests should handle ${} in the view of jtreg "smart action"
  • 26bb183: 8352621: MatchException from backwards incompatible change to switch expressions
  • e8c9e5c: 8353231: Test com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad still fails intermittently
  • 6ab1647: 8353637: ZGC: Discontiguous memory reservation is broken on Windows
  • c494a00: 8353559: Restructure CollectedHeap error printing
  • ... and 84 more: https://git.openjdk.org/jdk/compare/aff5aa72bbf4ecea614339483581093a67efa265...master

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 (@djelinski, @dfuch) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 4, 2025
@openjdk
Copy link

openjdk bot commented Apr 4, 2025

@tabata-d The following label will be automatically applied to this pull request:

  • net

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.

@openjdk openjdk bot added the net net-dev@openjdk.org label Apr 4, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 4, 2025

Webrevs

Copy link
Member

@djelinski djelinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for addressing the issues!

@openjdk
Copy link

openjdk bot commented Apr 4, 2025

⚠️ @tabata-d the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout fix_simplewebserver
$ git commit --author='Preferred Full Name <you@example.com>' --allow-empty -m 'Update full name'
$ git push

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 4, 2025
@dfuch
Copy link
Member

dfuch commented Apr 4, 2025

Hi, it's not completely clear to me why static final String LOCALE_OPT = "-Duser.language=en -Duser.country=US"; has now to be passed to every test that checks command line options. Is that a separate unrelated test fix?

@tabata-d
Copy link
Contributor Author

tabata-d commented Apr 4, 2025

@dfuch Thank you for your comment.

Is that a separate unrelated test fix?

No, it's related.

For example, after this modification, if you run jwebserver --help on Japanese Windows without specifying a locale, it will be output in Japanese as follows:

> jwebserver.exe --help
使用方法: jwebserver [-b bind address] [-p port] [-d directory]
                  [-o none|info|verbose] [-h to show options]
                  [-version to show version information]
オプション:
-b, --bind-address    - バインド先アドレス。デフォルト: 127.0.0.1 (ループバック)。
                        すべてのインタフェースで"-b 0.0.0.0"または"-b ::"を使用します。
-d, --directory       - 使用するディレクトリ。デフォルト: 現在のディレクトリ。
-o, --output          - 出力形式。none|info|verbose。デフォルト: info。
-p, --port            - リスニングするポート。デフォルト: 8000。
-h, -?, --help        - ヘルプ・メッセージを出力して終了します。
-version, --version   - バージョン情報を出力して終了します。
サーバーを停止するには、[Ctrl]+[C]を押します。

This is the same in jtreg tests, so if you test it on Japanese Windows, it will fail.
By specifying the English locale to jwebserver or java -m jdk.httpserver, you can get English output even on Japanese Windows, so the test will be Passed.

@tabata-d
Copy link
Contributor Author

tabata-d commented Apr 4, 2025

Upon reconsideration, these tests were failing on Japanese OS even before the fix.
Should I issue a separate Bug ID?

@dfuch
Copy link
Member

dfuch commented Apr 4, 2025

Upon reconsideration, these tests were failing on Japanese Windows even before the fix.
Should I issue a separate Bug ID?

That's what I suspected. I just wanted to make sure that needing the locale was not a side effect of your changes.
That said - I believe our tests are typically expecting the CI system (or make)? to set Locale.ENGLISH before running the tests.

I'm good with the changes you're proposing. Please hold on integrating for a bit - I would like to verify that there no regression in our CI.

@@ -65,7 +63,7 @@ public static void main(String... args) {
setMaxReqTime();
setMaxConnectionsIfNotSet();

int ec = SimpleFileServerImpl.start(new PrintWriter(System.out, true, UTF_8), "jwebserver", args);
int ec = SimpleFileServerImpl.start(new PrintWriter(System.out, true), "jwebserver", args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are looking for stdout.encoding here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting changing this line @AlanBateman? The API doc of PrintWriter(OutputStream, boolean) says:

     * Creates a new PrintWriter from an existing OutputStream.  This
     * convenience constructor creates the necessary intermediate
     * OutputStreamWriter, which will convert characters into bytes using
     * the default charset, or where {@code out} is a {@code PrintStream},
     * the charset used by the print stream.

Isn't this what we want here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just paging in the changes we did in JDK 10. They are the same thing as System.out will be created to use stdout.encoding. So you can ignore my comment.

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My tests came back green. Thanks for fixing this issue!

@tabata-d
Copy link
Contributor Author

tabata-d commented Apr 7, 2025

Thank you for the reviews!
/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Apr 7, 2025
@openjdk
Copy link

openjdk bot commented Apr 7, 2025

@tabata-d
Your change (at version 0bc8e19) is now ready to be sponsored by a Committer.

@Michael-Mc-Mahon
Copy link
Member

LGTM also.

@Michael-Mc-Mahon
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Apr 9, 2025

Going to push as commit f7fa05f.
Since your change was applied there have been 152 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 9, 2025
@openjdk openjdk bot closed this Apr 9, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Apr 9, 2025
@openjdk
Copy link

openjdk bot commented Apr 9, 2025

@Michael-Mc-Mahon @tabata-d Pushed as commit f7fa05f.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@tabata-d tabata-d deleted the fix_simplewebserver branch April 9, 2025 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated net net-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

5 participants