Skip to content

Commit

Permalink
8289797: tools/launcher/I18NArgTest.java fails on Japanese Windows en…
Browse files Browse the repository at this point in the history
…vironment

Reviewed-by: naoto
  • Loading branch information
tkiriyama authored and naotoj committed Sep 27, 2022
1 parent 7151128 commit a11477c
Showing 1 changed file with 48 additions and 25 deletions.
73 changes: 48 additions & 25 deletions test/jdk/tools/launcher/I18NArgTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -31,6 +31,8 @@
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
import java.util.HexFormat;
import java.nio.charset.StandardCharsets;

public class I18NArgTest extends TestHelper {
public static void main(String... args) throws IOException {
Expand Down Expand Up @@ -66,21 +68,21 @@ static void execTest(int unicodeValue) {
execTest("*" + unicodeStr + unicodeStr + "*", hexValue + hexValue);
execTest("?" + unicodeStr + unicodeStr + "?", hexValue + hexValue);

execTest("\"" + unicodeStr + "a" + unicodeStr + "\"", hexValue + "61" + hexValue);
execTest("\\" + unicodeStr + "a" + unicodeStr + "\\", hexValue + "61" + hexValue);
execTest(" " + unicodeStr + "a" + unicodeStr + " ", hexValue + "61"+ hexValue);
execTest("'" + unicodeStr + "a" + unicodeStr + "'", hexValue + "61"+ hexValue);
execTest("\t" + unicodeStr + "a" + unicodeStr + "\t", hexValue + "61"+ hexValue);
execTest("*" + unicodeStr + "a" + unicodeStr + "*", hexValue + "61"+ hexValue);
execTest("?" + unicodeStr + "a" + unicodeStr + "?", hexValue + "61"+ hexValue);
execTest("\"" + unicodeStr + "a" + unicodeStr + "\"", hexValue + "0061" + hexValue);
execTest("\\" + unicodeStr + "a" + unicodeStr + "\\", hexValue + "0061" + hexValue);
execTest(" " + unicodeStr + "a" + unicodeStr + " ", hexValue + "0061"+ hexValue);
execTest("'" + unicodeStr + "a" + unicodeStr + "'", hexValue + "0061"+ hexValue);
execTest("\t" + unicodeStr + "a" + unicodeStr + "\t", hexValue + "0061"+ hexValue);
execTest("*" + unicodeStr + "a" + unicodeStr + "*", hexValue + "0061"+ hexValue);
execTest("?" + unicodeStr + "a" + unicodeStr + "?", hexValue + "0061"+ hexValue);

execTest("\"" + unicodeStr + "\u00b1" + unicodeStr + "\"", hexValue + "b1" + hexValue);
execTest("\\" + unicodeStr + "\u00b1" + unicodeStr + "\\", hexValue + "b1" + hexValue);
execTest(" " + unicodeStr + "\u00b1" + unicodeStr + " ", hexValue + "b1"+ hexValue);
execTest("'" + unicodeStr + "\u00b1" + unicodeStr + "'", hexValue + "b1"+ hexValue);
execTest("\t" + unicodeStr + "\u00b1" + unicodeStr + "\t", hexValue + "b1"+ hexValue);
execTest("*" + unicodeStr + "\u00b1" + unicodeStr + "*", hexValue + "b1"+ hexValue);
execTest("?" + unicodeStr + "\u00b1" + unicodeStr + "?", hexValue + "b1"+ hexValue);
execTest("\"" + unicodeStr + "\u00b1" + unicodeStr + "\"", hexValue + "00b1" + hexValue);
execTest("\\" + unicodeStr + "\u00b1" + unicodeStr + "\\", hexValue + "00b1" + hexValue);
execTest(" " + unicodeStr + "\u00b1" + unicodeStr + " ", hexValue + "00b1"+ hexValue);
execTest("'" + unicodeStr + "\u00b1" + unicodeStr + "'", hexValue + "00b1"+ hexValue);
execTest("\t" + unicodeStr + "\u00b1" + unicodeStr + "\t", hexValue + "00b1"+ hexValue);
execTest("*" + unicodeStr + "\u00b1" + unicodeStr + "*", hexValue + "00b1"+ hexValue);
execTest("?" + unicodeStr + "\u00b1" + unicodeStr + "?", hexValue + "00b1"+ hexValue);
}

static void execTest(String unicodeStr, String hexValue) {
Expand All @@ -97,12 +99,21 @@ static void execTest(String unicodeStr, String hexValue) {

// Test via JDK_JAVA_OPTIONS
Map<String, String> env = new HashMap<>();
String cmd = "-Dtest.src=" + TEST_SOURCES_DIR.getAbsolutePath() +
" -Dtest.classes=" + TEST_CLASSES_DIR.getAbsolutePath() +
" -cp " + TEST_CLASSES_DIR.getAbsolutePath() +
" I18NArgTest " + unicodeStr + " " + hexValue;
env.put("JDK_JAVA_OPTIONS", cmd);
tr = doExec(env, javaCmd);
String sysPropName = "foo.bar";
// When pass "-Dfoo.bar=<unicodestr>" via the JDK_JAVA_OPTIONS environment variable,
// we expect that system property value to be passed along to the main method with the
// correct encoding
// If <unicodestr> contains space or tab, it should be enclosed with double quotes.
if (unicodeStr.contains(" ") || unicodeStr.contains("\t")) {
unicodeStr = "\"" + unicodeStr + "\"";
}
String jdkJavaOpts = "-D" + sysPropName + "=" + unicodeStr;
env.put("JDK_JAVA_OPTIONS", jdkJavaOpts);
tr = doExec(env,javaCmd,
"-Dtest.src=" + TEST_SOURCES_DIR.getAbsolutePath(),
"-Dtest.classes=" + TEST_CLASSES_DIR.getAbsolutePath(),
"-cp", TEST_CLASSES_DIR.getAbsolutePath(),
"I18NArgTest", unicodeStr, hexValue, sysPropName);
System.out.println(tr.testOutput);
if (!tr.isOK()) {
System.err.println(tr);
Expand All @@ -113,10 +124,7 @@ static void execTest(String unicodeStr, String hexValue) {
static void testCharacters(String... args) {
String input = args[0];
String expected = args[1];
String hexValue = "";
for (int i = 0; i < input.length(); i++) {
hexValue = hexValue.concat(Integer.toHexString((int)input.charAt(i)));
}
var hexValue = HexFormat.of().formatHex(input.getBytes(StandardCharsets.UTF_16));
System.out.println("input:" + input);
System.out.println("expected:" + expected);
System.out.println("obtained:" + hexValue);
Expand All @@ -125,5 +133,20 @@ static void testCharacters(String... args) {
"expected:" + expected + " obtained:" + hexValue;
throw new RuntimeException(message);
}
if (args.length == 3) {
// verify the value of the system property matches the expected value
String sysPropName = args[2];
String sysPropVal = System.getProperty(sysPropName);
if (sysPropVal == null) {
throw new RuntimeException("Missing system property " + sysPropName);
}
var sysPropHexVal = HexFormat.of().formatHex(sysPropVal.getBytes(StandardCharsets.UTF_16));
System.out.println("System property " + sysPropName + " computed hex value: "
+ sysPropHexVal);
if (!sysPropHexVal.contains(expected)) {
throw new RuntimeException("Unexpected value in system property, expected "
+ expected + ", but got " + sysPropHexVal);
}
}
}
}

3 comments on commit a11477c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on a11477c Aug 8, 2023

Choose a reason for hiding this comment

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

@TheRealMDoerr the backport was successfully created on the branch TheRealMDoerr-backport-a11477ce in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit a11477ce from the openjdk/jdk repository.

The commit being backported was authored by KIRIYAMA Takuya on 27 Sep 2022 and was reviewed by Naoto Sato.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git TheRealMDoerr-backport-a11477ce:TheRealMDoerr-backport-a11477ce
$ git checkout TheRealMDoerr-backport-a11477ce
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git TheRealMDoerr-backport-a11477ce

Please sign in to comment.