Skip to content

Commit c018c43

Browse files
committed
Merge branch '3.3.x'
Closes gh-42736
2 parents 12c1d70 + 8efe6e0 commit c018c43

File tree

37 files changed

+229
-38
lines changed

37 files changed

+229
-38
lines changed

buildSrc/src/main/java/org/springframework/boot/build/antora/AntoraAsciidocAttributes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ public synchronized Object put(Object key, Object value) {
191191
};
192192
try (InputStream in = getClass().getResourceAsStream("antora-asciidoc-attributes.properties")) {
193193
properties.load(in);
194-
} catch (IOException ex) {
194+
}
195+
catch (IOException ex) {
195196
throw new UncheckedIOException(ex);
196197
}
197198
}

buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2024 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,7 +89,8 @@ public ArchitectureCheck() {
8989
noClassesShouldCallStepVerifierStepVerifyComplete(),
9090
noClassesShouldConfigureDefaultStepVerifierTimeout(), noClassesShouldCallCollectorsToList(),
9191
noClassesShouldCallURLEncoderWithStringEncoding(), noClassesShouldCallURLDecoderWithStringEncoding(),
92-
noClassesShouldLoadResourcesUsingResourceUtils());
92+
noClassesShouldLoadResourcesUsingResourceUtils(), noClassesShouldCallStringToUpperCaseWithoutLocale(),
93+
noClassesShouldCallStringToLowerCaseWithoutLocale());
9394
getRules().addAll(getProhibitObjectsRequireNonNull()
9495
.map((prohibit) -> prohibit ? noClassesShouldCallObjectsRequireNonNull() : Collections.emptyList()));
9596
getRuleDescriptions().set(getRules().map((rules) -> rules.stream().map(ArchRule::getDescription).toList()));
@@ -191,6 +192,20 @@ public void check(JavaMethod item, ConditionEvents events) {
191192
};
192193
}
193194

195+
private ArchRule noClassesShouldCallStringToLowerCaseWithoutLocale() {
196+
return ArchRuleDefinition.noClasses()
197+
.should()
198+
.callMethod(String.class, "toLowerCase")
199+
.because("String.toLowerCase(Locale.ROOT) should be used instead");
200+
}
201+
202+
private ArchRule noClassesShouldCallStringToUpperCaseWithoutLocale() {
203+
return ArchRuleDefinition.noClasses()
204+
.should()
205+
.callMethod(String.class, "toUpperCase")
206+
.because("String.toUpperCase(Locale.ROOT) should be used instead");
207+
}
208+
194209
private ArchRule noClassesShouldCallStepVerifierStepVerifyComplete() {
195210
return ArchRuleDefinition.noClasses()
196211
.should()

buildSrc/src/main/java/org/springframework/boot/build/artifacts/ArtifactRelease.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.build.artifacts;
1818

19+
import java.util.Locale;
20+
1921
import org.gradle.api.Project;
2022

2123
/**
@@ -37,7 +39,7 @@ private ArtifactRelease(Type type) {
3739
}
3840

3941
public String getType() {
40-
return this.type.toString().toLowerCase();
42+
return this.type.toString().toLowerCase(Locale.ROOT);
4143
}
4244

4345
public String getDownloadRepo() {

buildSrc/src/main/java/org/springframework/boot/build/bom/Library.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public Library(String name, String calendarName, LibraryVersion version, List<Gr
102102
}
103103

104104
private static String generateLinkRootName(String name) {
105-
return name.replace("-", "").replace(" ", "-").toLowerCase();
105+
return name.replace("-", "").replace(" ", "-").toLowerCase(Locale.ROOT);
106106
}
107107

108108
public String getName() {

buildSrc/src/main/java/org/springframework/boot/build/properties/BuildType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.build.properties;
1818

19+
import java.util.Locale;
20+
1921
/**
2022
* The type of build being performed.
2123
*
@@ -34,7 +36,7 @@ public enum BuildType {
3436
COMMERCIAL;
3537

3638
public String toIdentifier() {
37-
return toString().replace("_", "").toLowerCase();
39+
return toString().replace("_", "").toLowerCase(Locale.ROOT);
3840
}
3941

4042
}

buildSrc/src/test/java/org/springframework/boot/build/architecture/ArchitectureCheckTests.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,42 @@ void whenClassCallsObjectsRequireNonNullWithSupplierTaskFailsAndWritesReport() t
163163
});
164164
}
165165

166+
@Test
167+
void whenClassCallsStringToUpperCaseWithoutLocaleFailsAndWritesReport() throws Exception {
168+
prepareTask("string/toUpperCase", (architectureCheck) -> {
169+
assertThatExceptionOfType(GradleException.class).isThrownBy(architectureCheck::checkArchitecture);
170+
assertThat(failureReport(architectureCheck)).isNotEmpty()
171+
.content()
172+
.contains("because String.toUpperCase(Locale.ROOT) should be used instead");
173+
});
174+
}
175+
176+
@Test
177+
void whenClassCallsStringToLowerCaseWithoutLocaleFailsAndWritesReport() throws Exception {
178+
prepareTask("string/toLowerCase", (architectureCheck) -> {
179+
assertThatExceptionOfType(GradleException.class).isThrownBy(architectureCheck::checkArchitecture);
180+
assertThat(failureReport(architectureCheck)).isNotEmpty()
181+
.content()
182+
.contains("because String.toLowerCase(Locale.ROOT) should be used instead");
183+
});
184+
}
185+
186+
@Test
187+
void whenClassCallsStringToLowerCaseWithLocaleShouldNotFail() throws Exception {
188+
prepareTask("string/toLowerCaseWithLocale", (architectureCheck) -> {
189+
architectureCheck.checkArchitecture();
190+
assertThat(failureReport(architectureCheck)).isEmpty();
191+
});
192+
}
193+
194+
@Test
195+
void whenClassCallsStringToUpperCaseWithLocaleShouldNotFail() throws Exception {
196+
prepareTask("string/toUpperCaseWithLocale", (architectureCheck) -> {
197+
architectureCheck.checkArchitecture();
198+
assertThat(failureReport(architectureCheck)).isEmpty();
199+
});
200+
}
201+
166202
private void prepareTask(String classes, Callback<ArchitectureCheck> callback) throws Exception {
167203
File projectDir = new File(this.temp, "project");
168204
projectDir.mkdirs();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.architecture.string.toLowerCase;
18+
19+
class ToLowerCase {
20+
21+
void exampleMethod() {
22+
String test = "Object must not be null";
23+
System.out.println(test.toLowerCase());
24+
}
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.architecture.string.toLowerCaseWithLocale;
18+
19+
import java.util.Locale;
20+
21+
class ToLowerCaseWithLocale {
22+
23+
void exampleMethod() {
24+
String test = "Object must not be null";
25+
System.out.println(test.toLowerCase(Locale.ENGLISH));
26+
}
27+
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.architecture.string.toUpperCase;
18+
19+
class ToUpperCase {
20+
21+
void exampleMethod() {
22+
String test = "Object must not be null";
23+
System.out.println(test.toUpperCase());
24+
}
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.architecture.string.toUpperCaseWithLocale;
18+
19+
import java.util.Locale;
20+
21+
class ToUpperCaseWithLocale {
22+
23+
void exampleMethod() {
24+
String test = "Object must not be null";
25+
System.out.println(test.toUpperCase(Locale.ROOT));
26+
}
27+
28+
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnAvailableEndpointCondition.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.EnumSet;
2222
import java.util.LinkedHashSet;
2323
import java.util.List;
24+
import java.util.Locale;
2425
import java.util.Map;
2526
import java.util.Optional;
2627
import java.util.Set;
@@ -206,7 +207,7 @@ private static class StandardExposureOutcomeContributor implements EndpointExpos
206207

207208
StandardExposureOutcomeContributor(Environment environment, EndpointExposure exposure) {
208209
this.exposure = exposure;
209-
String name = exposure.name().toLowerCase().replace('_', '-');
210+
String name = exposure.name().toLowerCase(Locale.ROOT).replace('_', '-');
210211
this.property = "management.endpoints." + name + ".exposure";
211212
this.filter = new IncludeExcludeEndpointFilter<>(ExposableEndpoint.class, environment, this.property,
212213
exposure.getDefaultIncludes());

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/otlp/OtlpTracingConfigurations.java

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

1717
package org.springframework.boot.actuate.autoconfigure.tracing.otlp;
1818

19+
import java.util.Locale;
20+
1921
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
2022
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder;
2123
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
@@ -85,7 +87,7 @@ OtlpHttpSpanExporter otlpHttpSpanExporter(OtlpTracingProperties properties,
8587
.setEndpoint(connectionDetails.getUrl(Transport.HTTP))
8688
.setTimeout(properties.getTimeout())
8789
.setConnectTimeout(properties.getConnectTimeout())
88-
.setCompression(properties.getCompression().name().toLowerCase());
90+
.setCompression(properties.getCompression().name().toLowerCase(Locale.ROOT));
8991
properties.getHeaders().forEach(builder::addHeader);
9092
return builder.build();
9193
}
@@ -98,7 +100,7 @@ OtlpGrpcSpanExporter otlpGrpcSpanExporter(OtlpTracingProperties properties,
98100
.setEndpoint(connectionDetails.getUrl(Transport.GRPC))
99101
.setTimeout(properties.getTimeout())
100102
.setConnectTimeout(properties.getConnectTimeout())
101-
.setCompression(properties.getCompression().name().toLowerCase());
103+
.setCompression(properties.getCompression().name().toLowerCase(Locale.ROOT));
102104
properties.getHeaders().forEach(builder::addHeader);
103105
return builder.build();
104106
}

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/exchanges/HttpExchange.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.HashSet;
2626
import java.util.LinkedHashMap;
2727
import java.util.List;
28+
import java.util.Locale;
2829
import java.util.Map;
2930
import java.util.Set;
3031
import java.util.function.Supplier;
@@ -434,7 +435,7 @@ private static class HeadersFilter {
434435

435436
void excludeUnless(String header, Include exception) {
436437
if (!this.includes.contains(exception)) {
437-
this.filteredHeaderNames.add(header.toLowerCase());
438+
this.filteredHeaderNames.add(header.toLowerCase(Locale.ROOT));
438439
}
439440
}
440441

@@ -444,7 +445,7 @@ Map<String, List<String>> apply(Map<String, List<String>> headers) {
444445
}
445446
Map<String, List<String>> filtered = new LinkedHashMap<>();
446447
headers.forEach((name, value) -> {
447-
if (!this.filteredHeaderNames.contains(name.toLowerCase())) {
448+
if (!this.filteredHeaderNames.contains(name.toLowerCase(Locale.ROOT))) {
448449
filtered.put(name, value);
449450
}
450451
});

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/annotation/DiscoveredOperationMethodTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.actuate.endpoint.annotation;
1818

1919
import java.lang.reflect.Method;
20+
import java.util.Locale;
2021

2122
import org.junit.jupiter.api.Test;
2223

@@ -76,7 +77,7 @@ enum ExampleProducible implements Producible<ExampleProducible> {
7677

7778
@Override
7879
public MimeType getProducedMimeType() {
79-
return new MimeType(toString().toLowerCase());
80+
return new MimeType(toString().toLowerCase(Locale.ROOT));
8081
}
8182

8283
}

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/annotation/DiscoveredOperationsFactoryTests.java

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

2526
import org.junit.jupiter.api.BeforeEach;
@@ -254,7 +255,7 @@ enum ExampleProducible implements Producible<ExampleProducible> {
254255

255256
@Override
256257
public MimeType getProducedMimeType() {
257-
return new MimeType(toString().toLowerCase());
258+
return new MimeType(toString().toLowerCase(Locale.ROOT));
258259
}
259260

260261
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/PropertiesHazelcastConnectionDetails.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.io.UncheckedIOException;
2121
import java.net.URL;
22+
import java.util.Locale;
2223

2324
import com.hazelcast.client.config.ClientConfig;
2425
import com.hazelcast.client.config.XmlClientConfigBuilder;
@@ -54,7 +55,7 @@ public ClientConfig getClientConfig() {
5455
private ClientConfig loadClientConfig(Resource configLocation) {
5556
try {
5657
URL configUrl = configLocation.getURL();
57-
String configFileName = configUrl.getPath().toLowerCase();
58+
String configFileName = configUrl.getPath().toLowerCase(Locale.ROOT);
5859
return (!isYaml(configFileName)) ? new XmlClientConfigBuilder(configUrl).build()
5960
: new YamlClientConfigBuilder(configUrl).build();
6061
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerPropertiesMapper.java

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

1919
import java.util.ArrayList;
2020
import java.util.List;
21+
import java.util.Locale;
2122

2223
import org.springframework.boot.autoconfigure.security.oauth2.server.servlet.OAuth2AuthorizationServerProperties.Client;
2324
import org.springframework.boot.autoconfigure.security.oauth2.server.servlet.OAuth2AuthorizationServerProperties.Registration;
@@ -124,7 +125,7 @@ private TokenSettings getTokenSettings(Client client, PropertyMapper map) {
124125
}
125126

126127
private JwsAlgorithm jwsAlgorithm(String signingAlgorithm) {
127-
String name = signingAlgorithm.toUpperCase();
128+
String name = signingAlgorithm.toUpperCase(Locale.ROOT);
128129
JwsAlgorithm jwsAlgorithm = SignatureAlgorithm.from(name);
129130
if (jwsAlgorithm == null) {
130131
jwsAlgorithm = MacAlgorithm.from(name);
@@ -133,7 +134,7 @@ private JwsAlgorithm jwsAlgorithm(String signingAlgorithm) {
133134
}
134135

135136
private SignatureAlgorithm signatureAlgorithm(String signatureAlgorithm) {
136-
return SignatureAlgorithm.from(signatureAlgorithm.toUpperCase());
137+
return SignatureAlgorithm.from(signatureAlgorithm.toUpperCase(Locale.ROOT));
137138
}
138139

139140
}

0 commit comments

Comments
 (0)