Skip to content

Commit 6e7cd76

Browse files
author
Andrey Turbanov
committed
8291061: Improve thread safety of FileTime.toString and toInstant
Reviewed-by: alanb
1 parent 477f471 commit 6e7cd76

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/java.base/share/classes/java/nio/file/attribute/FileTime.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2022, 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
@@ -228,6 +228,7 @@ private static long scale(long d, long m, long over) {
228228
* @since 1.8
229229
*/
230230
public Instant toInstant() {
231+
Instant instant = this.instant;
231232
if (instant == null) {
232233
long secs = 0L;
233234
int nanos = 0;
@@ -269,6 +270,8 @@ else if (secs >= MAX_SECOND)
269270
instant = Instant.MAX;
270271
else
271272
instant = Instant.ofEpochSecond(secs, nanos);
273+
274+
this.instant = instant;
272275
}
273276
return instant;
274277
}
@@ -409,6 +412,7 @@ private StringBuilder append(StringBuilder sb, int w, int d) {
409412
*/
410413
@Override
411414
public String toString() {
415+
String valueAsString = this.valueAsString;
412416
if (valueAsString == null) {
413417
long secs = 0L;
414418
int nanos = 0;
@@ -469,6 +473,7 @@ public String toString() {
469473
}
470474
sb.append('Z');
471475
valueAsString = sb.toString();
476+
this.valueAsString = valueAsString;
472477
}
473478
return valueAsString;
474479
}

0 commit comments

Comments
 (0)