From b51cd9fd99d12f488c70ee5534681e982c8c1449 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 1 Dec 2022 11:09:40 -0800 Subject: [PATCH] core: Replace AtomicInteger.updateAndGet with compareAndSet updateAndGet is only available in API level 24+. It is unclear why AnimalSniffer didn't detect this. This was noticed when doing the import, but the Android CI has also been failing because of it. --- .../main/java/io/grpc/internal/RetriableStream.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/grpc/internal/RetriableStream.java b/core/src/main/java/io/grpc/internal/RetriableStream.java index c8c45c61f8..46da45aebd 100644 --- a/core/src/main/java/io/grpc/internal/RetriableStream.java +++ b/core/src/main/java/io/grpc/internal/RetriableStream.java @@ -225,9 +225,13 @@ abstract class RetriableStream implements ClientStream { @Nullable // returns null when cancelled private Substream createSubstream(int previousAttemptCount, boolean isTransparentRetry) { // increment only when >= 0, i.e. not cancelled - if (inFlightSubStreams.updateAndGet(value -> value < 0 ? value : value + 1) < 0) { - return null; - } + int inFlight; + do { + inFlight = inFlightSubStreams.get(); + if (inFlight < 0) { + return null; + } + } while (!inFlightSubStreams.compareAndSet(inFlight, inFlight + 1)); Substream sub = new Substream(previousAttemptCount); // one tracer per substream final ClientStreamTracer bufferSizeTracer = new BufferSizeTracer(sub);