Skip to content

Commit

Permalink
Merge branch '3.3.x'
Browse files Browse the repository at this point in the history
Closes gh-42736
  • Loading branch information
mhalbritter committed Oct 17, 2024
2 parents 12c1d70 + 8efe6e0 commit c018c43
Show file tree
Hide file tree
Showing 37 changed files with 229 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ public synchronized Object put(Object key, Object value) {
};
try (InputStream in = getClass().getResourceAsStream("antora-asciidoc-attributes.properties")) {
properties.load(in);
} catch (IOException ex) {
}
catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -89,7 +89,8 @@ public ArchitectureCheck() {
noClassesShouldCallStepVerifierStepVerifyComplete(),
noClassesShouldConfigureDefaultStepVerifierTimeout(), noClassesShouldCallCollectorsToList(),
noClassesShouldCallURLEncoderWithStringEncoding(), noClassesShouldCallURLDecoderWithStringEncoding(),
noClassesShouldLoadResourcesUsingResourceUtils());
noClassesShouldLoadResourcesUsingResourceUtils(), noClassesShouldCallStringToUpperCaseWithoutLocale(),
noClassesShouldCallStringToLowerCaseWithoutLocale());
getRules().addAll(getProhibitObjectsRequireNonNull()
.map((prohibit) -> prohibit ? noClassesShouldCallObjectsRequireNonNull() : Collections.emptyList()));
getRuleDescriptions().set(getRules().map((rules) -> rules.stream().map(ArchRule::getDescription).toList()));
Expand Down Expand Up @@ -191,6 +192,20 @@ public void check(JavaMethod item, ConditionEvents events) {
};
}

private ArchRule noClassesShouldCallStringToLowerCaseWithoutLocale() {
return ArchRuleDefinition.noClasses()
.should()
.callMethod(String.class, "toLowerCase")
.because("String.toLowerCase(Locale.ROOT) should be used instead");
}

private ArchRule noClassesShouldCallStringToUpperCaseWithoutLocale() {
return ArchRuleDefinition.noClasses()
.should()
.callMethod(String.class, "toUpperCase")
.because("String.toUpperCase(Locale.ROOT) should be used instead");
}

private ArchRule noClassesShouldCallStepVerifierStepVerifyComplete() {
return ArchRuleDefinition.noClasses()
.should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.build.artifacts;

import java.util.Locale;

import org.gradle.api.Project;

/**
Expand All @@ -37,7 +39,7 @@ private ArtifactRelease(Type type) {
}

public String getType() {
return this.type.toString().toLowerCase();
return this.type.toString().toLowerCase(Locale.ROOT);
}

public String getDownloadRepo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Library(String name, String calendarName, LibraryVersion version, List<Gr
}

private static String generateLinkRootName(String name) {
return name.replace("-", "").replace(" ", "-").toLowerCase();
return name.replace("-", "").replace(" ", "-").toLowerCase(Locale.ROOT);
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.build.properties;

import java.util.Locale;

/**
* The type of build being performed.
*
Expand All @@ -34,7 +36,7 @@ public enum BuildType {
COMMERCIAL;

public String toIdentifier() {
return toString().replace("_", "").toLowerCase();
return toString().replace("_", "").toLowerCase(Locale.ROOT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,42 @@ void whenClassCallsObjectsRequireNonNullWithSupplierTaskFailsAndWritesReport() t
});
}

@Test
void whenClassCallsStringToUpperCaseWithoutLocaleFailsAndWritesReport() throws Exception {
prepareTask("string/toUpperCase", (architectureCheck) -> {
assertThatExceptionOfType(GradleException.class).isThrownBy(architectureCheck::checkArchitecture);
assertThat(failureReport(architectureCheck)).isNotEmpty()
.content()
.contains("because String.toUpperCase(Locale.ROOT) should be used instead");
});
}

@Test
void whenClassCallsStringToLowerCaseWithoutLocaleFailsAndWritesReport() throws Exception {
prepareTask("string/toLowerCase", (architectureCheck) -> {
assertThatExceptionOfType(GradleException.class).isThrownBy(architectureCheck::checkArchitecture);
assertThat(failureReport(architectureCheck)).isNotEmpty()
.content()
.contains("because String.toLowerCase(Locale.ROOT) should be used instead");
});
}

@Test
void whenClassCallsStringToLowerCaseWithLocaleShouldNotFail() throws Exception {
prepareTask("string/toLowerCaseWithLocale", (architectureCheck) -> {
architectureCheck.checkArchitecture();
assertThat(failureReport(architectureCheck)).isEmpty();
});
}

@Test
void whenClassCallsStringToUpperCaseWithLocaleShouldNotFail() throws Exception {
prepareTask("string/toUpperCaseWithLocale", (architectureCheck) -> {
architectureCheck.checkArchitecture();
assertThat(failureReport(architectureCheck)).isEmpty();
});
}

private void prepareTask(String classes, Callback<ArchitectureCheck> callback) throws Exception {
File projectDir = new File(this.temp, "project");
projectDir.mkdirs();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.build.architecture.string.toLowerCase;

class ToLowerCase {

void exampleMethod() {
String test = "Object must not be null";
System.out.println(test.toLowerCase());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.build.architecture.string.toLowerCaseWithLocale;

import java.util.Locale;

class ToLowerCaseWithLocale {

void exampleMethod() {
String test = "Object must not be null";
System.out.println(test.toLowerCase(Locale.ENGLISH));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.build.architecture.string.toUpperCase;

class ToUpperCase {

void exampleMethod() {
String test = "Object must not be null";
System.out.println(test.toUpperCase());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.build.architecture.string.toUpperCaseWithLocale;

import java.util.Locale;

class ToUpperCaseWithLocale {

void exampleMethod() {
String test = "Object must not be null";
System.out.println(test.toUpperCase(Locale.ROOT));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.EnumSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -206,7 +207,7 @@ private static class StandardExposureOutcomeContributor implements EndpointExpos

StandardExposureOutcomeContributor(Environment environment, EndpointExposure exposure) {
this.exposure = exposure;
String name = exposure.name().toLowerCase().replace('_', '-');
String name = exposure.name().toLowerCase(Locale.ROOT).replace('_', '-');
this.property = "management.endpoints." + name + ".exposure";
this.filter = new IncludeExcludeEndpointFilter<>(ExposableEndpoint.class, environment, this.property,
exposure.getDefaultIncludes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

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

import java.util.Locale;

import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterBuilder;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
Expand Down Expand Up @@ -85,7 +87,7 @@ OtlpHttpSpanExporter otlpHttpSpanExporter(OtlpTracingProperties properties,
.setEndpoint(connectionDetails.getUrl(Transport.HTTP))
.setTimeout(properties.getTimeout())
.setConnectTimeout(properties.getConnectTimeout())
.setCompression(properties.getCompression().name().toLowerCase());
.setCompression(properties.getCompression().name().toLowerCase(Locale.ROOT));
properties.getHeaders().forEach(builder::addHeader);
return builder.build();
}
Expand All @@ -98,7 +100,7 @@ OtlpGrpcSpanExporter otlpGrpcSpanExporter(OtlpTracingProperties properties,
.setEndpoint(connectionDetails.getUrl(Transport.GRPC))
.setTimeout(properties.getTimeout())
.setConnectTimeout(properties.getConnectTimeout())
.setCompression(properties.getCompression().name().toLowerCase());
.setCompression(properties.getCompression().name().toLowerCase(Locale.ROOT));
properties.getHeaders().forEach(builder::addHeader);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
Expand Down Expand Up @@ -434,7 +435,7 @@ private static class HeadersFilter {

void excludeUnless(String header, Include exception) {
if (!this.includes.contains(exception)) {
this.filteredHeaderNames.add(header.toLowerCase());
this.filteredHeaderNames.add(header.toLowerCase(Locale.ROOT));
}
}

Expand All @@ -444,7 +445,7 @@ Map<String, List<String>> apply(Map<String, List<String>> headers) {
}
Map<String, List<String>> filtered = new LinkedHashMap<>();
headers.forEach((name, value) -> {
if (!this.filteredHeaderNames.contains(name.toLowerCase())) {
if (!this.filteredHeaderNames.contains(name.toLowerCase(Locale.ROOT))) {
filtered.put(name, value);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.boot.actuate.endpoint.annotation;

import java.lang.reflect.Method;
import java.util.Locale;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -76,7 +77,7 @@ enum ExampleProducible implements Producible<ExampleProducible> {

@Override
public MimeType getProducedMimeType() {
return new MimeType(toString().toLowerCase());
return new MimeType(toString().toLowerCase(Locale.ROOT));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;

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

@Override
public MimeType getProducedMimeType() {
return new MimeType(toString().toLowerCase());
return new MimeType(toString().toLowerCase(Locale.ROOT));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URL;
import java.util.Locale;

import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.client.config.XmlClientConfigBuilder;
Expand Down Expand Up @@ -54,7 +55,7 @@ public ClientConfig getClientConfig() {
private ClientConfig loadClientConfig(Resource configLocation) {
try {
URL configUrl = configLocation.getURL();
String configFileName = configUrl.getPath().toLowerCase();
String configFileName = configUrl.getPath().toLowerCase(Locale.ROOT);
return (!isYaml(configFileName)) ? new XmlClientConfigBuilder(configUrl).build()
: new YamlClientConfigBuilder(configUrl).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

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

private JwsAlgorithm jwsAlgorithm(String signingAlgorithm) {
String name = signingAlgorithm.toUpperCase();
String name = signingAlgorithm.toUpperCase(Locale.ROOT);
JwsAlgorithm jwsAlgorithm = SignatureAlgorithm.from(name);
if (jwsAlgorithm == null) {
jwsAlgorithm = MacAlgorithm.from(name);
Expand All @@ -133,7 +134,7 @@ private JwsAlgorithm jwsAlgorithm(String signingAlgorithm) {
}

private SignatureAlgorithm signatureAlgorithm(String signatureAlgorithm) {
return SignatureAlgorithm.from(signatureAlgorithm.toUpperCase());
return SignatureAlgorithm.from(signatureAlgorithm.toUpperCase(Locale.ROOT));
}

}
Loading

0 comments on commit c018c43

Please sign in to comment.