Skip to content

Commit

Permalink
8316540: StoreReproducibilityTest fails on some locales
Browse files Browse the repository at this point in the history
Backport-of: f7578e8048ee961f22b57ee2b7eed9e9ab783cf5
  • Loading branch information
zzambers authored and shipilev committed Oct 5, 2023
1 parent d9bb3ca commit 667e639
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions test/jdk/java/util/Properties/StoreReproducibilityTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023, 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 @@ -44,7 +44,7 @@
/*
* @test
* @summary Tests that the Properties.store() APIs generate output that is reproducible
* @bug 8231640 8282023
* @bug 8231640 8282023 8316540
* @library /test/lib
* @run driver StoreReproducibilityTest
*/
Expand Down Expand Up @@ -92,7 +92,7 @@ private static void testWithoutSecurityManager() throws Exception {
for (int i = 0; i < 5; i++) {
final Path tmpFile = Files.createTempFile("8231640", ".props");
storedFiles.add(tmpFile);
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
StoreTest.class.getName(),
tmpFile.toString(),
Expand Down Expand Up @@ -134,10 +134,10 @@ private static void testWithSecMgrExplicitPermission() throws Exception {
for (int i = 0; i < 5; i++) {
final Path tmpFile = Files.createTempFile("8231640", ".props");
storedFiles.add(tmpFile);
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
"-Djava.security.manager",
"-Djava.security.policy=" + policyFile.toString(),
"-Djava.security.policy=" + policyFile,
StoreTest.class.getName(),
tmpFile.toString(),
i % 2 == 0 ? "--use-outputstream" : "--use-writer");
Expand Down Expand Up @@ -178,10 +178,10 @@ private static void testWithSecMgrNoSpecificPermission() throws Exception {
for (int i = 0; i < 5; i++) {
final Path tmpFile = Files.createTempFile("8231640", ".props");
storedFiles.add(tmpFile);
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
"-Djava.security.manager",
"-Djava.security.policy=" + policyFile.toString(),
"-Djava.security.policy=" + policyFile,
StoreTest.class.getName(),
tmpFile.toString(),
i % 2 == 0 ? "--use-outputstream" : "--use-writer");
Expand All @@ -208,7 +208,7 @@ private static void testBlankSysPropValue() throws Exception {
for (int i = 0; i < 2; i++) {
final Path tmpFile = Files.createTempFile("8231640", ".props");
storedFiles.add(tmpFile);
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
StoreTest.class.getName(),
tmpFile.toString(),
Expand Down Expand Up @@ -240,8 +240,9 @@ private static void testBlankSysPropValue() throws Exception {
private static void testEmptySysPropValue() throws Exception {
for (int i = 0; i < 2; i++) {
final Path tmpFile = Files.createTempFile("8231640", ".props");
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + "",
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=",
"-Duser.timezone=UTC",
StoreTest.class.getName(),
tmpFile.toString(),
i % 2 == 0 ? "--use-outputstream" : "--use-writer");
Expand Down Expand Up @@ -271,7 +272,7 @@ private static void testNonDateSysPropValue() throws Exception {
for (int i = 0; i < 2; i++) {
final Path tmpFile = Files.createTempFile("8231640", ".props");
storedFiles.add(tmpFile);
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
StoreTest.class.getName(),
tmpFile.toString(),
Expand Down Expand Up @@ -300,7 +301,7 @@ private static void testMultiLineSysPropValue() throws Exception {
for (int i = 0; i < 2; i++) {
final Path tmpFile = Files.createTempFile("8231640", ".props");
storedFiles.add(tmpFile);
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
StoreTest.class.getName(),
tmpFile.toString(),
Expand Down Expand Up @@ -342,7 +343,7 @@ private static void testBackSlashInSysPropValue() throws Exception {
for (int i = 0; i < 2; i++) {
final Path tmpFile = Files.createTempFile("8231640", ".props");
storedFiles.add(tmpFile);
final ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(
final ProcessBuilder processBuilder = ProcessTools.createTestJvm(
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal,
StoreTest.class.getName(),
tmpFile.toString(),
Expand Down Expand Up @@ -416,6 +417,9 @@ private static void assertExpectedComment(final Path destFile,
* Verifies that the date comment in the {@code destFile} can be parsed using the
* "EEE MMM dd HH:mm:ss zzz uuuu" format and the time represented by it is {@link Date#after(Date) after}
* the passed {@code date}
* The JVM runtime to invoke this method should set the time zone to UTC, i.e, specify
* "-Duser.timezone=UTC" at the command line. Otherwise, it will fail with some time
* zones that have ambiguous short names, such as "IST"
*/
private static void assertCurrentDate(final Path destFile, final Date date) throws Exception {
final String dateComment = findNthComment(destFile, 2);
Expand All @@ -440,7 +444,7 @@ private static void assertCurrentDate(final Path destFile, final Date date) thro
private static String findNthComment(Path file, int commentIndex) throws IOException {
List<String> comments = new ArrayList<>();
try (final BufferedReader reader = Files.newBufferedReader(file)) {
String line = null;
String line;
while ((line = reader.readLine()) != null) {
if (line.startsWith("#")) {
comments.add(line.substring(1));
Expand Down

1 comment on commit 667e639

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.