Skip to content

Commit 4b38e7b

Browse files
committed
8346133: Refactor java.time.ZoneOffset caching
Reviewed-by: jlu, liach, rriggs
1 parent 18fdbd2 commit 4b38e7b

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/java.base/share/classes/java/time/ZoneOffset.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2026, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2025, Alibaba Group Holding Limited. All Rights Reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -87,9 +87,9 @@
8787
import java.util.concurrent.ConcurrentHashMap;
8888
import java.util.concurrent.ConcurrentMap;
8989
import java.util.concurrent.atomic.AtomicReferenceArray;
90+
import java.util.function.Supplier;
9091

9192
import jdk.internal.util.DecimalDigits;
92-
import jdk.internal.vm.annotation.Stable;
9393

9494
/**
9595
* A time-zone offset from Greenwich/UTC, such as {@code +02:00}.
@@ -178,8 +178,13 @@ public final class ZoneOffset
178178
/**
179179
* The zone rules for an offset will always return this offset. Cache it for efficiency.
180180
*/
181-
@Stable
182-
private transient ZoneRules rules;
181+
private final transient LazyConstant<ZoneRules> rules =
182+
LazyConstant.of(new Supplier<ZoneRules>() {
183+
@Override
184+
public ZoneRules get() {
185+
return ZoneRules.of(ZoneOffset.this);
186+
}
187+
});
183188

184189
//-----------------------------------------------------------------------
185190
/**
@@ -521,11 +526,7 @@ public String getId() {
521526
*/
522527
@Override
523528
public ZoneRules getRules() {
524-
ZoneRules rules = this.rules;
525-
if (rules == null) {
526-
rules = this.rules = ZoneRules.of(this);
527-
}
528-
return rules;
529+
return rules.get();
529530
}
530531

531532
@Override

0 commit comments

Comments
 (0)