Skip to content

Commit

Permalink
8291061: Improve thread safety of FileTime.toString and toInstant
Browse files Browse the repository at this point in the history
Reviewed-by: alanb
  • Loading branch information
Andrey Turbanov committed Aug 5, 2022
1 parent 477f471 commit 6e7cd76
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 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 @@ -228,6 +228,7 @@ private static long scale(long d, long m, long over) {
* @since 1.8
*/
public Instant toInstant() {
Instant instant = this.instant;
if (instant == null) {
long secs = 0L;
int nanos = 0;
Expand Down Expand Up @@ -269,6 +270,8 @@ else if (secs >= MAX_SECOND)
instant = Instant.MAX;
else
instant = Instant.ofEpochSecond(secs, nanos);

this.instant = instant;
}
return instant;
}
Expand Down Expand Up @@ -409,6 +412,7 @@ private StringBuilder append(StringBuilder sb, int w, int d) {
*/
@Override
public String toString() {
String valueAsString = this.valueAsString;
if (valueAsString == null) {
long secs = 0L;
int nanos = 0;
Expand Down Expand Up @@ -469,6 +473,7 @@ public String toString() {
}
sb.append('Z');
valueAsString = sb.toString();
this.valueAsString = valueAsString;
}
return valueAsString;
}
Expand Down

1 comment on commit 6e7cd76

@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.