From 4eb4d9d1de89c9dc2de8da0b89c1e6f8a9b5b7c8 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 27 Oct 2021 08:55:36 -0400 Subject: [PATCH] GH-1983: Fix New Sonar Issues --- .../kafka/core/DefaultKafkaProducerFactory.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java b/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java index 0f9ce7b3..437d9cf6 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/core/DefaultKafkaProducerFactory.java @@ -470,13 +470,12 @@ public class DefaultKafkaProducerFactory extends KafkaResourceFactory * @return the producerProperties or a copy with the transaction ID set */ private Map ensureExistingTransactionIdPrefixInProperties(Map producerProperties) { - String transactionIdPrefix = getTransactionIdPrefix(); - if (StringUtils.hasText(transactionIdPrefix)) { - if (!producerProperties.containsKey(ProducerConfig.TRANSACTIONAL_ID_CONFIG)) { - Map producerPropertiesWithTxnId = new HashMap<>(producerProperties); - producerPropertiesWithTxnId.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, transactionIdPrefix); - return producerPropertiesWithTxnId; - } + String txIdPrefix = getTransactionIdPrefix(); + if (StringUtils.hasText(txIdPrefix) + && !producerProperties.containsKey(ProducerConfig.TRANSACTIONAL_ID_CONFIG)) { + Map producerPropertiesWithTxnId = new HashMap<>(producerProperties); + producerPropertiesWithTxnId.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, txIdPrefix); + return producerPropertiesWithTxnId; } return producerProperties;