8299571: ZoneRulesProvider.registerProvider() can leave inconsistent state on failure

Reviewed-by: iris, rriggs, joehw
This commit is contained in:
Naoto Sato 2023-01-11 17:01:48 +00:00
parent 4cd87f1bda
commit c7716a0101
2 changed files with 99 additions and 1 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@ -316,6 +316,10 @@ public abstract class ZoneRulesProvider {
Objects.requireNonNull(zoneId, "zoneId");
ZoneRulesProvider old = ZONES.putIfAbsent(zoneId, provider);
if (old != null) {
// restore old state
ZONES.put(zoneId, old);
provider.provideZoneIds().stream()
.forEach(id -> ZONES.remove(id, provider));
throw new ZoneRulesException(
"Unable to register zone as one already registered with that ID: " + zoneId +
", currently loading from provider: " + provider);