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+
}

0 commit comments

Comments
 (0)