diff --git a/clients/src/main/java/org/apache/kafka/clients/producer/MockProducer.java b/clients/src/main/java/org/apache/kafka/clients/producer/MockProducer.java index 3e5cb9f5d5ab3..605deb1c06313 100644 --- a/clients/src/main/java/org/apache/kafka/clients/producer/MockProducer.java +++ b/clients/src/main/java/org/apache/kafka/clients/producer/MockProducer.java @@ -45,6 +45,7 @@ import java.util.Map; import java.util.Objects; import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicLong; /** * A mock of the producer interface you can use for testing code that uses Kafka. @@ -73,7 +74,7 @@ public class MockProducer implements Producer { private boolean transactionAborted; private boolean producerFenced; private boolean sentOffsets; - private long commitCount = 0L; + private final AtomicLong commitCount = new AtomicLong(0); private final List addedMetrics = new ArrayList<>(); public RuntimeException initTransactionException = null; @@ -235,7 +236,7 @@ public void commitTransaction() throws ProducerFencedException { this.transactionAborted = false; this.transactionInFlight = false; - ++this.commitCount; + this.commitCount.getAndIncrement(); } @Override @@ -491,7 +492,7 @@ public boolean sentOffsets() { } public long commitCount() { - return this.commitCount; + return this.commitCount.get(); } /** diff --git a/gradle/spotbugs-exclude.xml b/gradle/spotbugs-exclude.xml index 48fc1f3722c36..c2d2fa7012493 100644 --- a/gradle/spotbugs-exclude.xml +++ b/gradle/spotbugs-exclude.xml @@ -555,7 +555,6 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read These are possibly real bugs, and have not been evaluated, they were just bulk excluded to unblock upgrading Spotbugs. --> -