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>
private synchronized @NonNull ListenableFuture<?> destroyGroup() {
final var future = SettableFuture.<Void>create();
- if (!closeFuture.compareAndSet(null, future)) {
- return verifyNotNull(closeFuture.get());
+ final var witness = closeFuture.compareAndExchange(null, future);
+ if (witness != null) {
+ return witness;
}
if (serviceEntityReg != null) {