Skip to content

Commit f7578e8

Browse files
committed
8316540: StoreReproducibilityTest fails on some locales
Reviewed-by: joehw, jlu, jpai, alanb
1 parent b66ded9 commit f7578e8

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

test/jdk/java/util/Properties/StoreReproducibilityTest.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,7 @@
4444
/*
4545
* @test
4646
* @summary Tests that the Properties.store() APIs generate output that is reproducible
47-
* @bug 8231640 8282023
47+
* @bug 8231640 8282023 8316540
4848
* @library /test/lib
4949
* @run driver StoreReproducibilityTest
5050
*/
@@ -92,7 +92,7 @@ private static void testWithoutSecurityManager() throws Exception {
9292
for (int i = 0; i < 5; i++) {
9393
final Path tmpFile = Files.createTempFile("8231640", ".props");
9494
storedFiles.add(tmpFile);
95-
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
95+
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
9696
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
9797
StoreTest.class.getName(),
9898
tmpFile.toString(),
@@ -134,10 +134,10 @@ private static void testWithSecMgrExplicitPermission() throws Exception {
134134
for (int i = 0; i < 5; i++) {
135135
final Path tmpFile = Files.createTempFile("8231640", ".props");
136136
storedFiles.add(tmpFile);
137-
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
137+
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
138138
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
139139
"-Djava.security.manager",
140-
"-Djava.security.policy=" + policyFile.toString(),
140+
"-Djava.security.policy=" + policyFile,
141141
StoreTest.class.getName(),
142142
tmpFile.toString(),
143143
i % 2 == 0 ? "--use-outputstream" : "--use-writer");
@@ -178,10 +178,10 @@ private static void testWithSecMgrNoSpecificPermission() throws Exception {
178178
for (int i = 0; i < 5; i++) {
179179
final Path tmpFile = Files.createTempFile("8231640", ".props");
180180
storedFiles.add(tmpFile);
181-
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
181+
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
182182
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
183183
"-Djava.security.manager",
184-
"-Djava.security.policy=" + policyFile.toString(),
184+
"-Djava.security.policy=" + policyFile,
185185
StoreTest.class.getName(),
186186
tmpFile.toString(),
187187
i % 2 == 0 ? "--use-outputstream" : "--use-writer");
@@ -208,7 +208,7 @@ private static void testBlankSysPropValue() throws Exception {
208208
for (int i = 0; i < 2; i++) {
209209
final Path tmpFile = Files.createTempFile("8231640", ".props");
210210
storedFiles.add(tmpFile);
211-
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
211+
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
212212
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
213213
StoreTest.class.getName(),
214214
tmpFile.toString(),
@@ -240,8 +240,9 @@ private static void testBlankSysPropValue() throws Exception {
240240
private static void testEmptySysPropValue() throws Exception {
241241
for (int i = 0; i < 2; i++) {
242242
final Path tmpFile = Files.createTempFile("8231640", ".props");
243-
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
244-
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + "",
243+
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
244+
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=",
245+
"-Duser.timezone=UTC",
245246
StoreTest.class.getName(),
246247
tmpFile.toString(),
247248
i % 2 == 0 ? "--use-outputstream" : "--use-writer");
@@ -271,7 +272,7 @@ private static void testNonDateSysPropValue() throws Exception {
271272
for (int i = 0; i < 2; i++) {
272273
final Path tmpFile = Files.createTempFile("8231640", ".props");
273274
storedFiles.add(tmpFile);
274-
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
275+
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
275276
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
276277
StoreTest.class.getName(),
277278
tmpFile.toString(),
@@ -300,7 +301,7 @@ private static void testMultiLineSysPropValue() throws Exception {
300301
for (int i = 0; i < 2; i++) {
301302
final Path tmpFile = Files.createTempFile("8231640", ".props");
302303
storedFiles.add(tmpFile);
303-
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
304+
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
304305
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
305306
StoreTest.class.getName(),
306307
tmpFile.toString(),
@@ -342,7 +343,7 @@ private static void testBackSlashInSysPropValue() throws Exception {
342343
for (int i = 0; i < 2; i++) {
343344
final Path tmpFile = Files.createTempFile("8231640", ".props");
344345
storedFiles.add(tmpFile);
345-
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
346+
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
346347
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
347348
StoreTest.class.getName(),
348349
tmpFile.toString(),
@@ -416,6 +417,9 @@ private static void assertExpectedComment(final Path destFile,
416417
* Verifies that the date comment in the {@code destFile} can be parsed using the
417418
* "EEE MMM dd HH:mm:ss zzz uuuu" format and the time represented by it is {@link Date#after(Date) after}
418419
* the passed {@code date}
420+
* The JVM runtime to invoke this method should set the time zone to UTC, i.e, specify
421+
* "-Duser.timezone=UTC" at the command line. Otherwise, it will fail with some time
422+
* zones that have ambiguous short names, such as "IST"
419423
*/
420424
private static void assertCurrentDate(final Path destFile, final Date date) throws Exception {
421425
final String dateComment = findNthComment(destFile, 2);
@@ -440,7 +444,7 @@ private static void assertCurrentDate(final Path destFile, final Date date) thro
440444
private static String findNthComment(Path file, int commentIndex) throws IOException {
441445
List<String> comments = new ArrayList<>();
442446
try (final BufferedReader reader = Files.newBufferedReader(file)) {
443-
String line = null;
447+
String line;
444448
while ((line = reader.readLine()) != null) {
445449
if (line.startsWith("#")) {
446450
comments.add(line.substring(1));

0 commit comments

Comments
 (0)