Skip to content

Commit 8d16d8c

Browse files
committed
Specify locale in toLowerCase|toUpperCase
This commit makes sure that all usages of String toLowerCase and toUpperCase specify a Locale (default of Locale.ROOT).
1 parent 35c8b02 commit 8d16d8c

File tree

9 files changed

+38
-14
lines changed

9 files changed

+38
-14
lines changed

buildSrc/src/main/java/org/springframework/pulsar/gradle/JavaConventionsPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Arrays;
2020
import java.util.Collections;
21+
import java.util.Locale;
2122
import java.util.Map;
2223
import java.util.Set;
2324
import java.util.TreeMap;
@@ -204,7 +205,7 @@ private void configureDependencyManagement(Project project) {
204205
configuration.setCanBeResolved(false);
205206
});
206207
configurations
207-
.matching((c) -> c.getName().endsWith("Classpath") || c.getName().toLowerCase().endsWith("annotationprocessor"))
208+
.matching((c) -> c.getName().endsWith("Classpath") || c.getName().toLowerCase(Locale.ROOT).endsWith("annotationprocessor"))
208209
.all((c) -> c.extendsFrom(dependencyManagement));
209210
Dependency pulsarDependencies = project.getDependencies().enforcedPlatform(project.getDependencies()
210211
.project(Collections.singletonMap("path", ":spring-pulsar-dependencies")));

buildSrc/src/main/java/org/springframework/pulsar/gradle/docs/AsciidoctorConventionsPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.net.URI;
2121
import java.util.Collections;
2222
import java.util.HashMap;
23+
import java.util.Locale;
2324
import java.util.Map;
2425

2526
import org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask;
@@ -121,7 +122,7 @@ private void configureAsciidoctorTask(Project project, AbstractAsciidoctorTask a
121122
asciidoctorTask.baseDirFollowsSourceDir();
122123
createSyncDocumentationSourceTask(project, asciidoctorTask);
123124
if (asciidoctorTask instanceof AsciidoctorTask task) {
124-
boolean pdf = task.getName().toLowerCase().contains("pdf");
125+
boolean pdf = task.getName().toLowerCase(Locale.ROOT).contains("pdf");
125126
String backend = (!pdf) ? "spring-html" : "spring-pdf";
126127
task.outputOptions((outputOptions) -> outputOptions.backends(backend));
127128
}

gradle/version-catalog-update.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def isNonStable = { String version ->
44
if (unstableKeyword) {
55
return true
66
}
7-
def containsStableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
7+
def containsStableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase(Locale.ROOT).contains(it) }
88
def containsStableSuffix = (version ==~ /^[0-9,.v-]+(-r)?$/)
99
return !containsStableKeyword && !containsStableSuffix
1010
}

integration-tests/src/intTest/java/org/springframework/pulsar/inttest/function/PulsarFunctionAdministrationIntegrationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Arrays;
2626
import java.util.HashMap;
2727
import java.util.List;
28+
import java.util.Locale;
2829
import java.util.Map;
2930
import java.util.Objects;
3031
import java.util.concurrent.CountDownLatch;
@@ -222,7 +223,7 @@ static PulsarSource rabbitPulsarSource(@Nullable FunctionStopPolicy stopPolicy)
222223
// custom network and a network alias 'rabbitmq' and the exposed port '5672'.
223224
// This differs from typical RabbitTemplate/RabbitProperties coordinates which
224225
// require the mapped host and port (outside the container).
225-
String suffix = stopPolicy != null ? ("-" + stopPolicy.name().toLowerCase()) : "";
226+
String suffix = stopPolicy != null ? ("-" + stopPolicy.name().toLowerCase(Locale.ROOT)) : "";
226227
Map<String, Object> configs = new HashMap<>();
227228
configs.put("host", "rabbitmq");
228229
configs.put("port", 5672);

spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/pulsar/transactions.adoc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ A common transactional pattern is where a consumer reads messages from a Pulsar
8989
The framework supports this use case when transactions are enabled and your listener method uses a transactional `PulsarTemplate` to produce the transformed message.
9090

9191
Given the following listener method:
92-
[source, java]
92+
93+
[source,java]
9394
----
94-
@PulsarListener(topics = "my-input-topic") // <1>
95+
import java.util.Locale;@PulsarListener(topics = "my-input-topic") // <1>
9596
void listen(String msg) { // <2>
96-
var transformedMsg = msg.toUpperCase(); // <3>
97+
var transformedMsg = msg.toUpperCase(Locale.ROOT); // <3>
9798
this.transactionalTemplate.send("my-output-topic", transformedMsg); // <4>
9899
} // <5> <6>
99100
----
@@ -212,10 +213,10 @@ The DB transaction is committed first; if the Pulsar transaction fails to commit
212213

213214
[source,java]
214215
----
215-
@PulsarListener(topics = "my-input-topic")
216+
import java.util.Locale;@PulsarListener(topics = "my-input-topic")
216217
@Transactional("dataSourceTransactionManager")
217218
void listen(String msg) {
218-
var transformedMsg = msg.toUpperCase();
219+
var transformedMsg = msg.toUpperCase(Locale.ROOT);
219220
this.pulsarTemplate.send("my-output-topic", transformedMsg);
220221
this.jdbcTemplate.execute("insert into my_table (data) values ('%s')".formatted(transformedMsg));
221222
}

spring-pulsar/src/main/java/org/springframework/pulsar/function/PulsarFunctionAdministration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collections;
2121
import java.util.LinkedHashMap;
2222
import java.util.List;
23+
import java.util.Locale;
2324
import java.util.Map;
2425
import java.util.Optional;
2526
import java.util.stream.Stream;
@@ -314,7 +315,7 @@ private Optional<Exception> safeInvoke(Runnable invocation) {
314315
}
315316

316317
private String functionDesc(PulsarFunctionOperations<?> function) {
317-
return "'%s' %s".formatted(function.name(), function.type().toString().toLowerCase());
318+
return "'%s' %s".formatted(function.name(), function.type().toString().toLowerCase(Locale.ROOT));
318319
}
319320

320321
/**

spring-pulsar/src/main/java/org/springframework/pulsar/support/header/PulsarHeaderMatcher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.pulsar.support.header;
1818

19+
import java.util.Locale;
1920
import java.util.Set;
2021

2122
import org.springframework.core.log.LogAccessor;
@@ -92,13 +93,13 @@ public static PatternMatch fromPatternString(String pattern) {
9293

9394
public PatternMatch(String pattern, boolean negate) {
9495
Assert.notNull(pattern, "Pattern must not be null");
95-
this.pattern = pattern.toLowerCase();
96+
this.pattern = pattern.toLowerCase(Locale.ROOT);
9697
this.negate = negate;
9798
}
9899

99100
@Override
100101
public boolean matchHeader(String headerName) {
101-
if (!PatternMatchUtils.simpleMatch(this.pattern, headerName.toLowerCase())) {
102+
if (!PatternMatchUtils.simpleMatch(this.pattern, headerName.toLowerCase(Locale.ROOT))) {
102103
return false;
103104
}
104105
LOGGER.debug(() -> "headerName=[%s] WILL %s be mapped, matched pattern=%s".formatted(headerName,

spring-pulsar/src/test/java/org/springframework/pulsar/core/DefaultTopicResolverTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.mockito.Mockito.times;
2323
import static org.mockito.Mockito.verify;
2424

25+
import java.util.Locale;
2526
import java.util.stream.Stream;
2627

2728
import org.apache.pulsar.common.schema.SchemaType;
@@ -204,7 +205,7 @@ void spelExpressionIsResolved(@Autowired DefaultTopicResolver topicResolver) {
204205
@Test
205206
void embeddedExpressionIsResolved(@Autowired DefaultTopicResolver topicResolver) {
206207
assertThat(topicResolver.resolveTopic(null, MsgTypeWithTopicEmbeddedExpression.class, () -> defaultTopic)
207-
.value().orElse(null)).isEqualTo("my-custom-property-topic".toUpperCase());
208+
.value().orElse(null)).isEqualTo("my-custom-property-topic".toUpperCase(Locale.ROOT));
208209
}
209210
// @formatter:on
210211

@@ -226,7 +227,8 @@ record MsgTypeWithTopicPropertyExpression(String value) {
226227
record MsgTypeWithTopicSpELExpression(String value) {
227228
}
228229

229-
@PulsarMessage(topic = "#{T(java.lang.String).valueOf('${app.customPropertyTopic}').toUpperCase()}")
230+
@PulsarMessage(
231+
topic = "#{T(java.lang.String).valueOf('${app.customPropertyTopic}').toUpperCase(java.util.Locale.ROOT)}")
230232
record MsgTypeWithTopicEmbeddedExpression(String value) {
231233
}
232234

src/checkstyle/checkstyle.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@
169169
value="Please use AssertJ imports."/>
170170
<property name="ignoreComments" value="true"/>
171171
</module>
172+
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
173+
<property name="id" value="toLowerCaseWithoutLocale"/>
174+
<property name="format" value="\.toLowerCase\(\)"/>
175+
<property name="maximum" value="0"/>
176+
<property name="message"
177+
value="String.toLowerCase() should be String.toLowerCase(Locale.ROOT)"/>
178+
<property name="ignoreComments" value="true"/>
179+
</module>
180+
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
181+
<property name="id" value="toUpperCaseWithoutLocale"/>
182+
<property name="format" value="\.toUpperCase\(\)"/>
183+
<property name="maximum" value="0"/>
184+
<property name="message"
185+
value="String.toUpperCase() should be String.toUpperCase(Locale.ROOT)"/>
186+
<property name="ignoreComments" value="true"/>
187+
</module>
172188
<module name="Regexp">
173189
<property name="format" value="[ \t]+$"/>
174190
<property name="illegalPattern" value="true"/>

0 commit comments

Comments
 (0)