From ffa49ee3a3a6bb5530a0673f168a4c110b2bfc9b Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 31 Oct 2024 11:06:15 -0400 Subject: [PATCH] GH-3608: Use Locale.ROOT for neutral, case insensitive comparisons Fixes: #3608 Issue link: https://github.com/spring-projects/spring-kafka/issues/3608 (cherry picked from commit 07cff76a45b2f1e0437e809496de888265964c55) --- .../annotation/KafkaListenerAnnotationBeanPostProcessor.java | 3 ++- .../kafka/support/AbstractKafkaHeaderMapper.java | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessor.java b/spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessor.java index 00a0889cef..e4bca3a91e 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessor.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessor.java @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -1014,7 +1015,7 @@ else if (resolvedValue instanceof Integer intgr) { private TopicPartitionOffset.SeekPosition resloveTopicPartitionOffsetSeekPosition(@Nullable Object seekPosition) { TopicPartitionOffset.SeekPosition resloveTpoSp = null; if (seekPosition instanceof String seekPositionName) { - String capitalLetterSeekPositionName = seekPositionName.trim().toUpperCase(); + String capitalLetterSeekPositionName = seekPositionName.trim().toUpperCase(Locale.ROOT); if (SeekPosition.BEGINNING.name().equals(capitalLetterSeekPositionName)) { resloveTpoSp = SeekPosition.BEGINNING; } diff --git a/spring-kafka/src/main/java/org/springframework/kafka/support/AbstractKafkaHeaderMapper.java b/spring-kafka/src/main/java/org/springframework/kafka/support/AbstractKafkaHeaderMapper.java index 03f655b299..186a2f78b9 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/support/AbstractKafkaHeaderMapper.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/support/AbstractKafkaHeaderMapper.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -351,13 +352,13 @@ protected SimplePatternBasedHeaderMatcher(String pattern) { SimplePatternBasedHeaderMatcher(String pattern, boolean negate) { Assert.notNull(pattern, "Pattern must no be null"); - this.pattern = pattern.toLowerCase(); + this.pattern = pattern.toLowerCase(Locale.ROOT); this.negate = negate; } @Override public boolean matchHeader(String headerName) { - String header = headerName.toLowerCase(); + String header = headerName.toLowerCase(Locale.ROOT); if (PatternMatchUtils.simpleMatch(this.pattern, header)) { LOGGER.debug(() -> MessageFormat.format(