1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
44
44
/*
45
45
* @test
46
46
* @summary Tests that the Properties.store() APIs generate output that is reproducible
47
- * @bug 8231640 8282023
47
+ * @bug 8231640 8282023 8316540
48
48
* @library /test/lib
49
49
* @run driver StoreReproducibilityTest
50
50
*/
@@ -92,7 +92,7 @@ private static void testWithoutSecurityManager() throws Exception {
92
92
for (int i = 0 ; i < 5 ; i ++) {
93
93
final Path tmpFile = Files .createTempFile ("8231640" , ".props" );
94
94
storedFiles .add (tmpFile );
95
- final ProcessBuilder processBuilder = ProcessTools .createJavaProcessBuilder (
95
+ final ProcessBuilder processBuilder = ProcessTools .createTestJvm (
96
96
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal ,
97
97
StoreTest .class .getName (),
98
98
tmpFile .toString (),
@@ -134,10 +134,10 @@ private static void testWithSecMgrExplicitPermission() throws Exception {
134
134
for (int i = 0 ; i < 5 ; i ++) {
135
135
final Path tmpFile = Files .createTempFile ("8231640" , ".props" );
136
136
storedFiles .add (tmpFile );
137
- final ProcessBuilder processBuilder = ProcessTools .createJavaProcessBuilder (
137
+ final ProcessBuilder processBuilder = ProcessTools .createTestJvm (
138
138
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal ,
139
139
"-Djava.security.manager" ,
140
- "-Djava.security.policy=" + policyFile . toString () ,
140
+ "-Djava.security.policy=" + policyFile ,
141
141
StoreTest .class .getName (),
142
142
tmpFile .toString (),
143
143
i % 2 == 0 ? "--use-outputstream" : "--use-writer" );
@@ -178,10 +178,10 @@ private static void testWithSecMgrNoSpecificPermission() throws Exception {
178
178
for (int i = 0 ; i < 5 ; i ++) {
179
179
final Path tmpFile = Files .createTempFile ("8231640" , ".props" );
180
180
storedFiles .add (tmpFile );
181
- final ProcessBuilder processBuilder = ProcessTools .createJavaProcessBuilder (
181
+ final ProcessBuilder processBuilder = ProcessTools .createTestJvm (
182
182
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal ,
183
183
"-Djava.security.manager" ,
184
- "-Djava.security.policy=" + policyFile . toString () ,
184
+ "-Djava.security.policy=" + policyFile ,
185
185
StoreTest .class .getName (),
186
186
tmpFile .toString (),
187
187
i % 2 == 0 ? "--use-outputstream" : "--use-writer" );
@@ -208,7 +208,7 @@ private static void testBlankSysPropValue() throws Exception {
208
208
for (int i = 0 ; i < 2 ; i ++) {
209
209
final Path tmpFile = Files .createTempFile ("8231640" , ".props" );
210
210
storedFiles .add (tmpFile );
211
- final ProcessBuilder processBuilder = ProcessTools .createJavaProcessBuilder (
211
+ final ProcessBuilder processBuilder = ProcessTools .createTestJvm (
212
212
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal ,
213
213
StoreTest .class .getName (),
214
214
tmpFile .toString (),
@@ -240,8 +240,9 @@ private static void testBlankSysPropValue() throws Exception {
240
240
private static void testEmptySysPropValue () throws Exception {
241
241
for (int i = 0 ; i < 2 ; i ++) {
242
242
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" ,
245
246
StoreTest .class .getName (),
246
247
tmpFile .toString (),
247
248
i % 2 == 0 ? "--use-outputstream" : "--use-writer" );
@@ -271,7 +272,7 @@ private static void testNonDateSysPropValue() throws Exception {
271
272
for (int i = 0 ; i < 2 ; i ++) {
272
273
final Path tmpFile = Files .createTempFile ("8231640" , ".props" );
273
274
storedFiles .add (tmpFile );
274
- final ProcessBuilder processBuilder = ProcessTools .createJavaProcessBuilder (
275
+ final ProcessBuilder processBuilder = ProcessTools .createTestJvm (
275
276
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal ,
276
277
StoreTest .class .getName (),
277
278
tmpFile .toString (),
@@ -300,7 +301,7 @@ private static void testMultiLineSysPropValue() throws Exception {
300
301
for (int i = 0 ; i < 2 ; i ++) {
301
302
final Path tmpFile = Files .createTempFile ("8231640" , ".props" );
302
303
storedFiles .add (tmpFile );
303
- final ProcessBuilder processBuilder = ProcessTools .createJavaProcessBuilder (
304
+ final ProcessBuilder processBuilder = ProcessTools .createTestJvm (
304
305
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal ,
305
306
StoreTest .class .getName (),
306
307
tmpFile .toString (),
@@ -342,7 +343,7 @@ private static void testBackSlashInSysPropValue() throws Exception {
342
343
for (int i = 0 ; i < 2 ; i ++) {
343
344
final Path tmpFile = Files .createTempFile ("8231640" , ".props" );
344
345
storedFiles .add (tmpFile );
345
- final ProcessBuilder processBuilder = ProcessTools .createJavaProcessBuilder (
346
+ final ProcessBuilder processBuilder = ProcessTools .createTestJvm (
346
347
"-D" + SYS_PROP_JAVA_PROPERTIES_DATE + "=" + sysPropVal ,
347
348
StoreTest .class .getName (),
348
349
tmpFile .toString (),
@@ -416,6 +417,9 @@ private static void assertExpectedComment(final Path destFile,
416
417
* Verifies that the date comment in the {@code destFile} can be parsed using the
417
418
* "EEE MMM dd HH:mm:ss zzz uuuu" format and the time represented by it is {@link Date#after(Date) after}
418
419
* 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"
419
423
*/
420
424
private static void assertCurrentDate (final Path destFile , final Date date ) throws Exception {
421
425
final String dateComment = findNthComment (destFile , 2 );
@@ -440,7 +444,7 @@ private static void assertCurrentDate(final Path destFile, final Date date) thro
440
444
private static String findNthComment (Path file , int commentIndex ) throws IOException {
441
445
List <String > comments = new ArrayList <>();
442
446
try (final BufferedReader reader = Files .newBufferedReader (file )) {
443
- String line = null ;
447
+ String line ;
444
448
while ((line = reader .readLine ()) != null ) {
445
449
if (line .startsWith ("#" )) {
446
450
comments .add (line .substring (1 ));
0 commit comments