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

8293579: tools/jpackage/share/jdk/jpackage/tests/UnicodeArgsTest.java fails on Japanese Windows platform #10226

Closed
wants to merge 2 commits into from

Conversation

tkiriyama
Copy link
Contributor

@tkiriyama tkiriyama commented Sep 9, 2022

Could you please review the JDK-8293579 bug fixes?

tools/jpackage/share/jdk/jpackage/tests/UnicodeArgsTest.java attempts to give
the launcher the character which is encoded by Windows API WideCharToMultiByte()
from UNICODE "é"(0x00e9) as an argument. However, this test fails because the
code point "é"(0x00e9) cannot be treated on Japanese Windows.

WideCharToMultiByte() encodes characters as Shift-JIS on Japanese Windows, but
the code point "é"(0x00e9) does not exist in Shift-JIS, and it is replaced with
"e"(0x0065) as substitute. Therefore, "é"(0x00e9) and "e"(0x0065) are compared
in this test and judged to be different characters, and return as failed.

So, in the Japanese encoding("MS932", "SJIS"), the test should be modified to
give a character such as "あ"(0x3042) as the launcher's argument instead of
"é"(0x00e9).


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-8293579: tools/jpackage/share/jdk/jpackage/tests/UnicodeArgsTest.java fails on Japanese Windows platform

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10226

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 9, 2022

👋 Welcome back tkiriyama! 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 openjdk bot added the rfr Pull request is ready for review label Sep 9, 2022
@openjdk
Copy link

openjdk bot commented Sep 9, 2022

@tkiriyama The following label will be automatically applied to this pull request:

  • core-libs

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 core-libs core-libs-dev@openjdk.org label Sep 9, 2022
@mlbridge
Copy link

mlbridge bot commented Sep 9, 2022

Webrevs

@naotoj
Copy link
Member

naotoj commented Sep 9, 2022

I just wonder if the fix is working as intended... Since JDK18, file.encoding is always UTF-8 with JEP 400, so the switch expression seems to fall into the default clause?

@tkiriyama
Copy link
Contributor Author

I just wonder if the fix is working as intended... Since JDK18, file.encoding is always UTF-8 with JEP 400, so the switch expression seems to fall into the default clause?

You’re right. file.encoding may not be useful for this test. I will think about other methods to check the encording. Do you have a good idea about that?

@naotoj
Copy link
Member

naotoj commented Sep 14, 2022

native.encoding holds the host encoding that used to be file.encoding.
Another suggestion is that, the test should only run in encodings that are guaranteed to succeed, e.g., Cp1252 or UTF-8, otherwise it should gracefully exit. Your proposed fix could still fail in locales/encodings other than SJIS/MS932.

@tkiriyama
Copy link
Contributor Author

@naotoj
Thank you for your help. I fixed this test to use native.encoding.
It is difficult to add all the encodings, so I will fix for Japanese and would like people who need other languages to do the same.

@alexeysemenyukoracle
Copy link
Member

It is difficult to add all the encodings, so I will fix for Japanese and would like people who need other languages to do the same.

It would be good to have a comment in the source code describing that this works only for Japanese encodings then.


String encoding = System.getProperty("native.encoding");
switch (encoding) {
default:
Copy link
Member

@naotoj naotoj Sep 28, 2022

Choose a reason for hiding this comment

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

What I meant by the previous comment was to replace this default clause to:

    case "Cp1252", "UTF-8" -> testString = new String(Character.toChars(0x00E9));

And for other unknown encodings:

    default -> {
        System.out.println("Test skipped"); // or better message
        return;
    }

And your fix:

    case "MS932", "SJIS" -> testString = new String(Character.toChars(0x3042));

This way only the encodings that are guaranteed to succeed are tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am sorry to misunderstand your comment.

I don’t know whether "é"(0x00e9) exists only in "Cp1252", "UTF-8".
Will that be no problem that this test is skipped in other encordings? If skipped, the pattern for its encording probably won't be added forever. I think the other pattern should be added when this test fails. However I will follow the policy of OpenJDK.

Choose a reason for hiding this comment

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

I agree skipping the test is not the best solution. Leaving a hint in the comments on how to fix the issue looks better alternative.

Copy link
Member

Choose a reason for hiding this comment

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

Well, what concerns me with the current fix is that it is simply patching only the case for the Japanese setup. We don't know if the same failure would happen in other setups (I'm pretty sure the same failure would happen with some Chinese Windows setups) which makes the test fragile. If that happens, we are not sure if it is a real bug or a test case false positive at a glance. For that reason, I think we should only run tests on the setup where we are sure the false positive won't happen (by skipping other unknown host encodings). And for the purpose of this test, that should suffice the need.
Another option would be to actually check if the test string can be encoded with a CharsetEncoder, but that may be overkill.

Choose a reason for hiding this comment

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

I don't think it will be many practical setups where this test fails. This test has been around for more than 2 years and this is the first accident.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least, the results in different encodings are the same as before the fix.
How about not fixing the pattern for other encordings to avoid false negative?

Copy link
Member

@alexeysemenyukoracle alexeysemenyukoracle Oct 3, 2022

Choose a reason for hiding this comment

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

This looks good to me. The only requirement to the value of testString is that it is a letter outside of the Basic Latin character set. So picking a letter that can be encoded in the active encoding works.

Copy link
Member

Choose a reason for hiding this comment

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

Although I still prefer preventing possible errors in the test, the change does not make it worse than before.

@mlbridge
Copy link

mlbridge bot commented Oct 3, 2022

Mailing list message from John Platts on core-libs-dev:

The issue can be worked around on Windows 10 Version 1903 or later (including Windows 11) by modifying the src/java.base/windows/native/launcher/java.manifest file as follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0"
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"

<assemblyIdentity
name=""
version=""
processorArchitecture="X86"
type="win32"
/>
<description>Java(TM) SE process</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>

<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>

<!-- Indicate JDK is high-dpi aware. -->
<asmv3:application>
<asmv3:windowsSettings xmlns:dpi1="http://schemas.microsoft.com/SMI/2005/WindowsSettings"
xmlns:dpi2="http://schemas.microsoft.com/SMI/2016/WindowsSettings"
xmlns:utf8="http://schemas.microsoft.com/SMI/2019/WindowsSettings">
<dpi1:dpiAware>true/PM</dpi1:dpiAware>
<dpi2:dpiAwareness>PerMonitorV2, PerMonitor, system</dpi2:dpiAwareness>
<!-- Use UTF-8 as the active code page on Windows 10 version 1903 or later -->
<utf8:activeCodePage>UTF-8</utf8:activeCodePage>
</asmv3:windowsSettings>
</asmv3:application>

<!-- Indicate this JDK version is Windows 7 compatible -->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
</assembly>

The GetACP() and GetOEMCP() functions will both return 65001 on Windows 10 Version 1903 or later if the above changes are made to src/java.base/windows/native/launcher/java.manifest.

Also make sure that the sun.jnu.encoding property is set to UTF-8 if GetACP() returns 65001.

Note that it is possible for GetACP() and GetOEMCP() to return values other than 65001 on Windows 10 Version 1809 or earlier or if the JVM is embedded in an application that does not have the <utf8:activeCodePage>UTF-8</utf8:activeCodePage> setting in its manifest.

________________________________
From: core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of Naoto Sato <naoto at openjdk.org>
Sent: Wednesday, September 28, 2022 1:03 PM
To: core-libs-dev at openjdk.org <core-libs-dev at openjdk.org>
Subject: Re: RFR: 8293579: tools/jpackage/share/jdk/jpackage/tests/UnicodeArgsTest.java fails on Japanese Windows platform [v2]

On Wed, 28 Sep 2022 09:45:32 GMT, KIRIYAMA Takuya <duke at openjdk.org> wrote:

Could you please review the JDK-8293579 bug fixes?

tools/jpackage/share/jdk/jpackage/tests/UnicodeArgsTest.java attempts to give
the launcher the character which is encoded by Windows API WideCharToMultiByte()
from UNICODE "?"(0x00e9) as an argument. However, this test fails because the
code point "?"(0x00e9) cannot be treated on Japanese Windows.

WideCharToMultiByte() encodes characters as Shift-JIS on Japanese Windows, but
the code point "?"(0x00e9) does not exist in Shift-JIS, and it is replaced with
"e"(0x0065) as substitute. Therefore, "?"(0x00e9) and "e"(0x0065) are compared
in this test and judged to be different characters, and return as failed.

So, in the Japanese encoding("MS932", "SJIS"), the test should be modified to
give a character such as "?"(0x3042) as the launcher's argument instead of
"?"(0x00e9).

KIRIYAMA Takuya has updated the pull request incrementally with one additional commit since the last revision:

8293579: tools/jpackage/share/jdk/jpackage/tests/UnicodeArgsTest.java fails on Japanese Windows platform

test/jdk/tools/jpackage/share/jdk/jpackage/tests/UnicodeArgsTest.java line 55:

53: String encoding = System.getProperty("native.encoding");
54: switch (encoding) {
55: default:

What I meant by the previous comment was to replace this `default` clause to:

case "Cp1252", "UTF-8" -> testString = new String(Character.toChars(0x00E9));

And for other unknown encodings:

default -> {
System.out.println("Test skipped"); // or better message
return;
}

And your fix:

case "MS932", "SJIS" -> testString = new String(Character.toChars(0x3042));

This way only the encodings that are guaranteed to succeed are tested.

-------------

PR: https://git.openjdk.org/jdk/pull/10226
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20221003/729d085d/attachment-0001.htm>


String encoding = System.getProperty("native.encoding");
switch (encoding) {
default:
Copy link
Member

@alexeysemenyukoracle alexeysemenyukoracle Oct 3, 2022

Choose a reason for hiding this comment

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

This looks good to me. The only requirement to the value of testString is that it is a letter outside of the Basic Latin character set. So picking a letter that can be encoded in the active encoding works.

@openjdk
Copy link

openjdk bot commented Oct 3, 2022

@tkiriyama 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:

8293579: tools/jpackage/share/jdk/jpackage/tests/UnicodeArgsTest.java fails on Japanese Windows platform

Reviewed-by: asemenyuk, naoto, almatvee

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

  • 4d6668e: 8294242: JFR: jfr print doesn't handle infinite duration well
  • 5a9cd33: 8294509: The sign extension bug applies to 'public static int[] convertSeedBytesToInts(byte[] seed, int n, int z)' in RandomSupport
  • f03934e: 8294578: [PPC64] C2: Missing is_oop information when using disjoint compressed oops mode
  • 3b476a1: 8292847: Zero: Allow ergonomics to select the GC
  • 16047e8: 8292780: misc tests failed "assert(false) failed: graph should be schedulable"
  • bf39b18: 8288302: Shenandoah: SIGSEGV in vm maybe related to jit compiling xerces
  • f957ce9: 8294564: IGV: IllegalArgumentException for "Difference to current graph"
  • ae79af2: 8294740: Add cgroups keyword to TestDockerBasic.java
  • 07ed68e: 8288907: serviceability/jvmti/vthread/SuspendResume1/SuspendResume1.java fails with -XX:TieredStopAtLevel=2,3
  • 090cdfc: 8294726: Update URLs in minefield tests
  • ... and 277 more: https://git.openjdk.org/jdk/compare/9d6b0285f53599816c30393b87d16772ef6314b7...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 (@alexeysemenyukoracle, @naotoj, @sashamatveev) 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 ready Pull request is ready to be integrated label Oct 3, 2022
@naotoj
Copy link
Member

naotoj commented Oct 3, 2022

The issue can be worked around on Windows 10 Version 1903 or later (including Windows 11) by modifying the src/java.base/windows/native/launcher/java.manifest file as follows: <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"

This would be a good enhancement for the jpackage.

@tkiriyama
Copy link
Contributor Author

Thank you for all reviews. I hope this fix integrated.

@tkiriyama
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 4, 2022
@openjdk
Copy link

openjdk bot commented Oct 4, 2022

@tkiriyama
Your change (at version 2baff40) is now ready to be sponsored by a Committer.

@naotoj
Copy link
Member

naotoj commented Oct 4, 2022

/sponsor

@openjdk
Copy link

openjdk bot commented Oct 4, 2022

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

  • 1166a8a: 8292214: Memory leak in getAllConfigs of awt_GraphicsEnv.c:386
  • 3644e26: 8294673: JFR: Add SecurityProviderService#threshold to TestActiveSettingEvent.java
  • 085949a: 8294712: G1: Use index-base iteration for G1FlushHumongousCandidateRemSets
  • b850f05: 8294758: JFR: Docs build fails after changes to RecordedObject and Timespan
  • 2dbedf0: 8294406: Test runtime/handshake/HandshakeDirectTest.java failed: JVMTI_ERROR_WRONG_PHASE
  • 4d6668e: 8294242: JFR: jfr print doesn't handle infinite duration well
  • 5a9cd33: 8294509: The sign extension bug applies to 'public static int[] convertSeedBytesToInts(byte[] seed, int n, int z)' in RandomSupport
  • f03934e: 8294578: [PPC64] C2: Missing is_oop information when using disjoint compressed oops mode
  • 3b476a1: 8292847: Zero: Allow ergonomics to select the GC
  • 16047e8: 8292780: misc tests failed "assert(false) failed: graph should be schedulable"
  • ... and 282 more: https://git.openjdk.org/jdk/compare/9d6b0285f53599816c30393b87d16772ef6314b7...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 4, 2022

@naotoj @tkiriyama Pushed as commit 121d4a5.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants