Skip to content

Commit 34d2b09

Browse files
committed
Fix new Sonar smells
1 parent e2557a4 commit 34d2b09

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

spring-integration-kafka/src/main/java/org/springframework/integration/kafka/dsl/KafkaProducerMessageHandlerSpec.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.util.function.Consumer;
2222
import java.util.function.Function;
2323

24-
import org.apache.kafka.clients.producer.ProducerRecord;
25-
2624
import org.springframework.expression.Expression;
2725
import org.springframework.expression.common.LiteralExpression;
2826
import org.springframework.integration.dsl.ComponentsRegistration;
@@ -239,8 +237,8 @@ public S timestampExpression(Expression timestampExpression) {
239237
}
240238

241239
/**
242-
* Configure a SpEL expression to determine whether or not to flush the producer after
243-
* a send. By default the producer is flushed if a header {@code kafka_flush} has a
240+
* Configure a SpEL expression to determine whether to flush the producer after
241+
* a send. By default, the producer is flushed if a header {@code kafka_flush} has a
244242
* value {@link Boolean#TRUE}.
245243
* @param flushExpression the timestamp expression to use.
246244
* @return the spec.
@@ -251,8 +249,8 @@ public S flushExpression(String flushExpression) {
251249

252250
/**
253251
* Configure a {@link Function} that will be invoked at runtime to determine whether
254-
* or not to flush the producer after a send. By default the producer is flushed if a
255-
* header {@code kafka_flush} has a value {@link Boolean#TRUE}. Typically used with a
252+
* to flush the producer after send. By default, the producer is flushed if a
253+
* header {@code kafka_flush} has a value {@link Boolean#TRUE}. Typically, used with a
256254
* Java 8 Lambda expression:
257255
* <pre class="code">
258256
* {@code
@@ -268,8 +266,8 @@ public <P> S flush(Function<Message<P>, Boolean> flushFunction) {
268266
}
269267

270268
/**
271-
* Configure an {@link Expression} to determine whether or not to flush the producer
272-
* after a send. By default the producer is flushed if a header {@code kafka_flush}
269+
* Configure an {@link Expression} to determine whether to flush the producer
270+
* after a send. By default, the producer is flushed if a header {@code kafka_flush}
273271
* has a value {@link Boolean#TRUE}.
274272
* @param flushExpression the timestamp expression to use.
275273
* @return the spec.
@@ -293,7 +291,7 @@ public S sync(boolean sync) {
293291

294292
/**
295293
* Specify a timeout in milliseconds how long {@link KafkaProducerMessageHandler}
296-
* should wait wait for send operation results. Defaults to 10 seconds.
294+
* should wait for send operation results. Defaults to 10 seconds.
297295
* @param sendTimeout the timeout to wait for result fo send operation.
298296
* @return the spec.
299297
*/
@@ -379,8 +377,8 @@ public S futuresChannel(String futuresChannel) {
379377
}
380378

381379
/**
382-
* Set a {@link ProducerRecordCreator} to create the {@link ProducerRecord}. Ignored
383-
* if {@link #useTemplateConverter(boolean) useTemplateConverter} is true.
380+
* Set a {@link ProducerRecordCreator} to create the {@link org.apache.kafka.clients.producer.ProducerRecord}.
381+
* Ignored if {@link #useTemplateConverter(boolean) useTemplateConverter} is true.
384382
* @param creator the creator.
385383
* @return the spec.
386384
* @since 5.5.5
@@ -392,7 +390,7 @@ public S producerRecordCreator(ProducerRecordCreator<K, V> creator) {
392390

393391
/**
394392
* Set to true to use the template's message converter to create the
395-
* {@link ProducerRecord} instead of the
393+
* {@link org.apache.kafka.clients.producer.ProducerRecord} instead of the
396394
* {@link #producerRecordCreator(ProducerRecordCreator) producerRecordCreator}.
397395
* @param use true to use the converter.
398396
* @return the spec.
@@ -409,7 +407,8 @@ public S useTemplateConverter(boolean use) {
409407
* @param <K> the key type.
410408
* @param <V> the value type.
411409
*/
412-
public static class KafkaProducerMessageHandlerTemplateSpec<K, V> extends KafkaProducerMessageHandlerSpec<K, V, KafkaProducerMessageHandlerTemplateSpec<K, V>>
410+
public static class KafkaProducerMessageHandlerTemplateSpec<K, V>
411+
extends KafkaProducerMessageHandlerSpec<K, V, KafkaProducerMessageHandlerTemplateSpec<K, V>>
413412
implements ComponentsRegistration {
414413

415414
private final KafkaTemplateSpec<K, V> kafkaTemplateSpec;
@@ -428,6 +427,7 @@ public static class KafkaProducerMessageHandlerTemplateSpec<K, V> extends KafkaP
428427
*/
429428
public KafkaProducerMessageHandlerTemplateSpec<K, V> configureKafkaTemplate(
430429
Consumer<KafkaTemplateSpec<K, V>> configurer) {
430+
431431
Assert.notNull(configurer, "The 'configurer' cannot be null");
432432
configurer.accept(this.kafkaTemplateSpec);
433433
return _this();

spring-integration-kafka/src/main/java/org/springframework/integration/kafka/inbound/KafkaMessageSource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ public class KafkaMessageSource<K, V> extends AbstractMessageSource<Object> impl
138138

139139
private Duration closeTimeout = Duration.ofSeconds(DEFAULT_CLOSE_TIMEOUT);
140140

141-
public boolean newAssignment;
142-
143141
private volatile Consumer<K, V> consumer;
144142

145143
private volatile boolean pausing;
@@ -150,6 +148,8 @@ public class KafkaMessageSource<K, V> extends AbstractMessageSource<Object> impl
150148

151149
private volatile boolean stopped;
152150

151+
public volatile boolean newAssignment; // NOSONAR - direct access from inner
152+
153153
/**
154154
* Construct an instance with the supplied parameters. Fetching multiple
155155
* records per poll will be disabled.
@@ -415,7 +415,7 @@ public boolean isPaused() {
415415
return this.paused;
416416
}
417417

418-
@Override
418+
@Override // NOSONAR - not so complex
419419
protected synchronized Object doReceive() {
420420
if (this.stopped) {
421421
this.logger.debug("Message source is stopped; no records will be returned");

spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void removeTopic(String... topic) {
254254
}
255255
}
256256

257-
private synchronized void connectAndSubscribe() throws MqttException {
257+
private synchronized void connectAndSubscribe() throws MqttException { // NOSONAR
258258
MqttConnectOptions connectionOptions = this.clientFactory.getConnectionOptions();
259259
this.cleanSession = connectionOptions.isCleanSession();
260260
this.consumerStopAction = this.clientFactory.getConsumerStopAction();

spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/MqttHeaderMapper.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.mqtt.support;
1818

1919
import java.nio.charset.StandardCharsets;
20+
import java.util.Arrays;
2021
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
@@ -61,7 +62,9 @@ public class MqttHeaderMapper implements HeaderMapper<MqttProperties> {
6162
*/
6263
public void setInboundHeaderNames(String... inboundHeaderNames) {
6364
Assert.notNull(inboundHeaderNames, "'inboundHeaderNames' must not be null");
64-
this.inboundHeaderNames = inboundHeaderNames;
65+
String[] copy = Arrays.copyOf(inboundHeaderNames, inboundHeaderNames.length);
66+
Arrays.sort(copy);
67+
this.inboundHeaderNames = copy;
6568
}
6669

6770
/**
@@ -73,7 +76,9 @@ public void setInboundHeaderNames(String... inboundHeaderNames) {
7376
*/
7477
public void setOutboundHeaderNames(String... outboundHeaderNames) {
7578
Assert.notNull(outboundHeaderNames, "'outboundHeaderNames' must not be null");
76-
this.outboundHeaderNames = outboundHeaderNames;
79+
String[] copy = Arrays.copyOf(outboundHeaderNames, outboundHeaderNames.length);
80+
Arrays.sort(copy);
81+
this.outboundHeaderNames = copy;
7782
}
7883

7984
@Override

0 commit comments

Comments
 (0)