Skip to content

Commit 9e0936f

Browse files
committed
Fix Issues Reported by Sonar
1 parent bbc5003 commit 9e0936f

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

spring-kafka-test/src/main/java/org/springframework/kafka/test/EmbeddedKafkaBroker.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,21 @@ public class EmbeddedKafkaBroker implements InitializingBean, DisposableBean {
119119

120120
public static final int DEFAULT_ZK_SESSION_TIMEOUT = 6000;
121121

122-
private static final Method getBrokerState;
122+
private static final Method GET_BROKER_STATE_METHOD;
123123

124124
static {
125125
try {
126126
Method method = KafkaServer.class.getDeclaredMethod("brokerState");
127127
if (method.getReturnType().equals(AtomicReference.class)) {
128-
getBrokerState = method;
128+
GET_BROKER_STATE_METHOD = method;
129129
}
130130
else {
131-
getBrokerState = null;
131+
GET_BROKER_STATE_METHOD = null;
132132
}
133133
}
134134
catch (NoSuchMethodException | SecurityException e) {
135-
throw new RuntimeException("Failed to determine KafkaServer.brokerState() method; client version: "
136-
+ AppInfoParser.getVersion());
135+
throw new IllegalStateException("Failed to determine KafkaServer.brokerState() method; client version: "
136+
+ AppInfoParser.getVersion(), e);
137137
}
138138
}
139139

@@ -579,9 +579,9 @@ public void destroy() {
579579
}
580580

581581
private boolean brokerRunning(KafkaServer kafkaServer) {
582-
if (getBrokerState != null) {
582+
if (GET_BROKER_STATE_METHOD != null) {
583583
try {
584-
return !getBrokerState.invoke(kafkaServer).toString().equals("NOT_RUNNING");
584+
return !GET_BROKER_STATE_METHOD.invoke(kafkaServer).toString().equals("NOT_RUNNING");
585585
}
586586
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
587587
throw new IllegalStateException(ex);

spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaConsumerBackoffManager.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import org.apache.kafka.clients.consumer.Consumer;
2020
import org.apache.kafka.common.TopicPartition;
2121

22-
import org.springframework.lang.Nullable;
23-
2422
/**
2523
* Interface for backing off a {@link MessageListenerContainer}
2624
* until a given dueTimestamp, if such timestamp is in the future.
@@ -34,7 +32,7 @@ public interface KafkaConsumerBackoffManager {
3432
void backOffIfNecessary(Context context);
3533

3634
default Context createContext(long dueTimestamp, String listenerId, TopicPartition topicPartition,
37-
@Nullable Consumer<?, ?> messageConsumer) {
35+
Consumer<?, ?> messageConsumer) {
3836
return new Context(dueTimestamp, topicPartition, listenerId, messageConsumer);
3937
}
4038

@@ -66,7 +64,7 @@ class Context {
6664
private final Consumer<?, ?> consumerForTimingAdjustment;
6765

6866
Context(long dueTimestamp, TopicPartition topicPartition, String listenerId,
69-
@Nullable Consumer<?, ?> consumerForTimingAdjustment) {
67+
Consumer<?, ?> consumerForTimingAdjustment) {
7068

7169
this.dueTimestamp = dueTimestamp;
7270
this.listenerId = listenerId;
@@ -86,7 +84,7 @@ public TopicPartition getTopicPartition() {
8684
return this.topicPartition;
8785
}
8886

89-
public @Nullable Consumer<?, ?> getConsumerForTimingAdjustment() {
87+
public Consumer<?, ?> getConsumerForTimingAdjustment() {
9088
return this.consumerForTimingAdjustment;
9189
}
9290

spring-kafka/src/main/java/org/springframework/kafka/listener/PartitionPausingBackoffManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private long applyTimingAdjustment(Context context, long timeUntilDue, long poll
196196
"Skipping timing adjustment for TopicPartition %s.", context.getTopicPartition()));
197197
return 0L;
198198
}
199-
return this.kafkaConsumerTimingAdjuster.adjustTiming(
199+
return this.kafkaConsumerTimingAdjuster.adjustTiming( // NOSONAR
200200
context.getConsumerForTimingAdjustment(),
201201
context.getTopicPartition(), pollTimeout, timeUntilDue);
202202
}

spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/KafkaBackoffAwareMessageListenerAdapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ private void invokeDelegateOnMessage(ConsumerRecord<K, V> consumerRecord, Acknow
116116
}
117117
}
118118

119-
private KafkaConsumerBackoffManager.Context createContext(ConsumerRecord<K, V> data, long nextExecutionTimestamp, Consumer<?, ?> consumer) {
119+
private KafkaConsumerBackoffManager.Context createContext(ConsumerRecord<K, V> data, long nextExecutionTimestamp,
120+
Consumer<?, ?> consumer) {
121+
120122
return this.kafkaConsumerBackoffManager.createContext(nextExecutionTimestamp, this.listenerId,
121123
new TopicPartition(data.topic(), data.partition()), consumer);
122124
}

spring-kafka/src/main/java/org/springframework/kafka/support/converter/BatchMessagingMessageConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void setRawRecordHeader(boolean rawRecordHeader) {
135135
this.rawRecordHeader = rawRecordHeader;
136136
}
137137

138-
@Override
138+
@Override // NOSONAR
139139
public Message<?> toMessage(List<ConsumerRecord<?, ?>> records, @Nullable Acknowledgment acknowledgment,
140140
Consumer<?, ?> consumer, Type type) {
141141

0 commit comments

Comments
 (0)