Java 9+ gives us a convenient way to ensure null-safety in this CAS
operation -- compareAndExchange() returns the witness value, i.e.
we get the value instead of a plain boolean false.
Change-Id: I636b0f084170d42bbd99490577917afefe5145e2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
b61b30a4b2be38c8629bf9c5d66d05609db3be1c)
(cherry picked from commit
aebfa4e09d2b35c8da3fb88d8a5883d84dab6b11)
}
private synchronized @NonNull ListenableFuture<?> destroyGroup() {
- final SettableFuture<Void> future = SettableFuture.create();
- if (!closeFuture.compareAndSet(null, future)) {
- return verifyNotNull(closeFuture.get());
+ final var future = SettableFuture.<Void>create();
+ final var witness = closeFuture.compareAndExchange(null, future);
+ if (witness != null) {
+ return witness;
}
if (serviceEntityReg != null) {