Skip to content

Commit b275384

Browse files
committed
Sonar fixes
1 parent 0c5867e commit b275384

File tree

7 files changed

+28
-14
lines changed

7 files changed

+28
-14
lines changed

spring-kafka-test/src/main/java/org/springframework/kafka/test/utils/KafkaTestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public static OffsetAndMetadata getCurrentOffset(String brokerAddresses, String
235235

236236
try (AdminClient client = AdminClient
237237
.create(Collections.singletonMap(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, brokerAddresses))) {
238-
return client.listConsumerGroupOffsets(group).partitionsToOffsetAndMetadata().get()
238+
return client.listConsumerGroupOffsets(group).partitionsToOffsetAndMetadata().get() // NOSONAR false positive
239239
.get(new TopicPartition(topic, partition));
240240
}
241241
}

spring-kafka/src/main/java/org/springframework/kafka/config/StreamsBuilderFactoryBean.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ public synchronized void stop() {
337337
if (this.cleanupConfig.cleanupOnStop()) {
338338
this.kafkaStreams.cleanUp();
339339
}
340-
this.listeners.forEach(listener -> listener.streamsRemoved(this.beanName, this.kafkaStreams));
340+
for (Listener listener : this.listeners) {
341+
listener.streamsRemoved(this.beanName, this.kafkaStreams);
342+
}
341343
this.kafkaStreams = null;
342344
}
343345
}

spring-kafka/src/main/java/org/springframework/kafka/core/KafkaFailureCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public interface KafkaFailureCallback<K, V> extends FailureCallback {
3434

3535
@Override
3636
default void onFailure(Throwable ex) {
37-
onFailure((KafkaProducerException) ex);
37+
onFailure((KafkaProducerException) ex); // NOSONAR (unchecked cast)
3838
}
3939

4040
/**

spring-kafka/src/main/java/org/springframework/kafka/core/RoutingKafkaTemplate.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
*/
4545
public class RoutingKafkaTemplate extends KafkaTemplate<Object, Object> {
4646

47+
private static final String THIS_METHOD_IS_NOT_SUPPORTED = "This method is not supported";
48+
4749
private final Map<Pattern, ProducerFactory<Object, Object>> factoryMatchers;
4850

4951
private final ConcurrentMap<String, ProducerFactory<Object, Object>> factoryMap = new ConcurrentHashMap<>();
@@ -72,7 +74,7 @@ public Producer<Object, Object> createProducer() {
7274

7375
@Override
7476
public ProducerFactory<Object, Object> getProducerFactory() {
75-
throw new UnsupportedOperationException("This method is not supported");
77+
throw new UnsupportedOperationException(THIS_METHOD_IS_NOT_SUPPORTED);
7678
}
7779

7880
@Override
@@ -91,27 +93,27 @@ public ProducerFactory<Object, Object> getProducerFactory(String topic) {
9193

9294
@Override
9395
public <T> T execute(ProducerCallback<Object, Object, T> callback) {
94-
throw new UnsupportedOperationException("This method is not supported");
96+
throw new UnsupportedOperationException(THIS_METHOD_IS_NOT_SUPPORTED);
9597
}
9698

9799
@Override
98100
public <T> T executeInTransaction(OperationsCallback<Object, Object, T> callback) {
99-
throw new UnsupportedOperationException("This method is not supported");
101+
throw new UnsupportedOperationException(THIS_METHOD_IS_NOT_SUPPORTED);
100102
}
101103

102104
@Override
103105
public void sendOffsetsToTransaction(Map<TopicPartition, OffsetAndMetadata> offsets, String consumerGroupId) {
104-
throw new UnsupportedOperationException("This method is not supported");
106+
throw new UnsupportedOperationException(THIS_METHOD_IS_NOT_SUPPORTED);
105107
}
106108

107109
@Override
108110
public Map<MetricName, ? extends Metric> metrics() {
109-
throw new UnsupportedOperationException("This method is not supported");
111+
throw new UnsupportedOperationException(THIS_METHOD_IS_NOT_SUPPORTED);
110112
}
111113

112114
@Override
113115
public void flush() {
114-
throw new UnsupportedOperationException("This method is not supported");
116+
throw new UnsupportedOperationException(THIS_METHOD_IS_NOT_SUPPORTED);
115117
}
116118

117119
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ protected void checkTopics() {
348348
.filter(entry -> AdminClientConfig.configNames().contains(entry.getKey()))
349349
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
350350
List<String> missing = null;
351-
try (AdminClient client = AdminClient.create(configs)) {
351+
try (AdminClient client = AdminClient.create(configs)) { // NOSONAR - false positive null check
352352
if (client != null) {
353353
String[] topics = this.containerProperties.getTopics();
354354
if (topics == null) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ public boolean equals(Object obj) {
8585
if (!(obj instanceof ConsumerRecordMetadata)) {
8686
return false;
8787
}
88-
return this.delegate.equals(obj)
89-
&& this.timestampType.equals(((ConsumerRecordMetadata) obj).timestampType());
88+
ConsumerRecordMetadata crm = (ConsumerRecordMetadata) obj;
89+
return this.delegate.equals(crm.delegate)
90+
&& this.timestampType.equals(crm.timestampType());
9091
}
9192

9293
@Override

spring-kafka/src/main/java/org/springframework/kafka/support/serializer/SerializationUtils.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,19 @@ public static <P, T> BiFunction<P, Headers, T> propertyToMethodInvokingFunction(
7373
method = clazz.getDeclaredMethod(methodName, payloadType);
7474
}
7575
catch (@SuppressWarnings("unused") NoSuchMethodException e1) {
76-
throw new IllegalStateException("the parser method must take '(String, Headers)' or '(String)'");
76+
IllegalStateException ise =
77+
new IllegalStateException("the parser method must take '("
78+
+ payloadType.getSimpleName()
79+
+ ", Headers)' or '("
80+
+ payloadType.getSimpleName()
81+
+ ")'", e1);
82+
ise.addSuppressed(e);
83+
throw ise;
7784
}
7885
catch (SecurityException e1) {
79-
throw new IllegalStateException(e1);
86+
IllegalStateException ise = new IllegalStateException(e1);
87+
ise.addSuppressed(e);
88+
throw ise;
8089
}
8190
}
8291
catch (SecurityException e) {

0 commit comments

Comments
 (0)