Skip to content

Commit 8efe6e0

Browse files
committed
Merge branch '3.2.x' into 3.3.x
Closes gh-42735
2 parents 43c4baf + a306065 commit 8efe6e0

File tree

31 files changed

+215
-31
lines changed

31 files changed

+215
-31
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()));
@@ -189,6 +190,20 @@ public void check(JavaMethod item, ConditionEvents events) {
189190
};
190191
}
191192

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

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.EnumSet;
2121
import java.util.HashSet;
2222
import java.util.LinkedHashSet;
23+
import java.util.Locale;
2324
import java.util.Map;
2425
import java.util.Optional;
2526
import java.util.Set;
@@ -118,7 +119,7 @@ private ConditionOutcome getMatchOutcome(Environment environment,
118119
for (ExposureFilter exposureFilter : exposureFilters) {
119120
if (exposuresToCheck.contains(exposureFilter.getExposure()) && exposureFilter.isExposed(endpointId)) {
120121
return ConditionOutcome.match(message.because("marked as exposed by a 'management.endpoints."
121-
+ exposureFilter.getExposure().name().toLowerCase() + ".exposure' property"));
122+
+ exposureFilter.getExposure().name().toLowerCase(Locale.ROOT) + ".exposure' property"));
122123
}
123124
}
124125
return ConditionOutcome.noMatch(message.because("no 'management.endpoints' property marked it as exposed"));
@@ -187,7 +188,7 @@ private static String getCanonicalName(EndpointExposure exposure) {
187188
if (EndpointExposure.CLOUD_FOUNDRY.equals(exposure)) {
188189
return "cloud-foundry";
189190
}
190-
return exposure.name().toLowerCase();
191+
return exposure.name().toLowerCase(Locale.ROOT);
191192
}
192193

193194
EndpointExposure getExposure() {

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

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

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

19+
import java.util.Locale;
1920
import java.util.Map.Entry;
2021

2122
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
@@ -78,7 +79,7 @@ OtlpHttpSpanExporter otlpHttpSpanExporter(OtlpProperties properties,
7879
OtlpHttpSpanExporterBuilder builder = OtlpHttpSpanExporter.builder()
7980
.setEndpoint(connectionDetails.getUrl())
8081
.setTimeout(properties.getTimeout())
81-
.setCompression(properties.getCompression().name().toLowerCase());
82+
.setCompression(properties.getCompression().name().toLowerCase(Locale.ROOT));
8283
for (Entry<String, String> header : properties.getHeaders().entrySet()) {
8384
builder.addHeader(header.getKey(), header.getValue());
8485
}

0 commit comments

Comments
 (0)