diff --git a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java index 774bdd431d..4f9217847e 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java @@ -70,15 +70,15 @@ public abstract class ArchitectureCheck extends DefaultTask { @TaskAction void checkArchitecture() throws IOException { JavaClasses javaClasses = new ClassFileImporter() - .importPaths(this.classes.getFiles().stream().map(File::toPath).collect(Collectors.toList())); + .importPaths(this.classes.getFiles().stream().map(File::toPath).toList()); List violations = Stream.of(allPackagesShouldBeFreeOfTangles(), allBeanPostProcessorBeanMethodsShouldBeStaticAndHaveParametersThatWillNotCausePrematureInitialization(), allBeanFactoryPostProcessorBeanMethodsShouldBeStaticAndHaveNoParameters(), noClassesShouldCallStepVerifierStepVerifyComplete(), - noClassesShouldConfigureDefaultStepVerifierTimeout()) + noClassesShouldConfigureDefaultStepVerifierTimeout(), noClassesShouldCallCollectorsToList()) .map((rule) -> rule.evaluate(javaClasses)) .filter(EvaluationResult::hasViolation) - .collect(Collectors.toList()); + .toList(); File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile(); outputFile.getParentFile().mkdirs(); if (!violations.isEmpty()) { @@ -178,6 +178,13 @@ public abstract class ArchitectureCheck extends DefaultTask { .because("expectComplete().verify(Duration) should be used instead"); } + private ArchRule noClassesShouldCallCollectorsToList() { + return ArchRuleDefinition.noClasses() + .should() + .callMethod(Collectors.class, "toList") + .because("java.util.stream.Stream.toList() should be used instead"); + } + public void setClasses(FileCollection classes) { this.classes = classes; } diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java index 31d6da0bc3..bcfb1406c5 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java @@ -103,7 +103,7 @@ class StandardLibraryUpdateResolver implements LibraryUpdateResolver { .flatMap(SortedSet::stream) .distinct() .filter((dependencyVersion) -> isPermitted(dependencyVersion, library.getProhibitedVersions())) - .collect(Collectors.toList()); + .toList(); if (allVersions.isEmpty()) { return Collections.emptyList(); } diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/ArtifactCollector.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/ArtifactCollector.java index 04ab265f25..d1d466f5b7 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/ArtifactCollector.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/ArtifactCollector.java @@ -50,7 +50,7 @@ class ArtifactCollector { Collection collectArtifacts(Path root) { try (Stream artifacts = Files.walk(root)) { return artifacts.filter(Files::isRegularFile).filter(this.excludeFilter) - .map((artifact) -> deployableArtifact(artifact, root)).collect(Collectors.toList()); + .map((artifact) -> deployableArtifact(artifact, root)).toList(); } catch (IOException ex) { throw new RuntimeException("Could not read artifacts from '" + root + "'"); diff --git a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java index da92b0c207..ed57036621 100644 --- a/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java +++ b/ci/images/releasescripts/src/main/java/io/spring/concourse/releasescripts/sonatype/SonatypeService.java @@ -208,7 +208,7 @@ public class SonatypeService { List failureMessages = Stream.of(activities).flatMap((activity) -> activity.events.stream()) .filter((event) -> event.severity > 0).flatMap((event) -> event.properties.stream()) .filter((property) -> "failureMessage".equals(property.name)) - .map((property) -> " " + property.value).collect(Collectors.toList()); + .map((property) -> " " + property.value).toList(); if (failureMessages.isEmpty()) { logger.error("Close failed for unknown reasons"); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/flyway/FlywayEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/flyway/FlywayEndpoint.java index 0922fb2455..6e42748a9a 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/flyway/FlywayEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/flyway/FlywayEndpoint.java @@ -21,7 +21,6 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.flywaydb.core.Flyway; @@ -116,7 +115,7 @@ public class FlywayEndpoint { private final List migrations; private FlywayDescriptor(MigrationInfo[] migrations) { - this.migrations = Stream.of(migrations).map(FlywayMigrationDescriptor::new).collect(Collectors.toList()); + this.migrations = Stream.of(migrations).map(FlywayMigrationDescriptor::new).toList(); } public FlywayDescriptor(List migrations) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java index 458493c982..a55337e58a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java @@ -16,8 +16,6 @@ package org.springframework.boot.autoconfigure.jms.activemq; -import java.util.stream.Collectors; - import jakarta.jms.ConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.commons.pool2.PooledObject; @@ -60,8 +58,7 @@ class ActiveMQConnectionFactoryConfiguration { private static ActiveMQConnectionFactory createJmsConnectionFactory(ActiveMQProperties properties, ObjectProvider factoryCustomizers) { - return new ActiveMQConnectionFactoryFactory(properties, - factoryCustomizers.orderedStream().collect(Collectors.toList())) + return new ActiveMQConnectionFactoryFactory(properties, factoryCustomizers.orderedStream().toList()) .createConnectionFactory(ActiveMQConnectionFactory.class); } @@ -96,7 +93,7 @@ class ActiveMQConnectionFactoryConfiguration { JmsPoolConnectionFactory jmsConnectionFactory(ActiveMQProperties properties, ObjectProvider factoryCustomizers) { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties, - factoryCustomizers.orderedStream().collect(Collectors.toList())) + factoryCustomizers.orderedStream().toList()) .createConnectionFactory(ActiveMQConnectionFactory.class); return new JmsPoolConnectionFactoryFactory(properties.getPool()) .createPooledConnectionFactory(connectionFactory); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java index cf28767de1..4a7cbd214c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQXAConnectionFactoryConfiguration.java @@ -16,8 +16,6 @@ package org.springframework.boot.autoconfigure.jms.activemq; -import java.util.stream.Collectors; - import jakarta.jms.ConnectionFactory; import jakarta.transaction.TransactionManager; import org.apache.activemq.ActiveMQConnectionFactory; @@ -51,7 +49,7 @@ class ActiveMQXAConnectionFactoryConfiguration { ObjectProvider factoryCustomizers, XAConnectionFactoryWrapper wrapper) throws Exception { ActiveMQXAConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties, - factoryCustomizers.orderedStream().collect(Collectors.toList())) + factoryCustomizers.orderedStream().toList()) .createConnectionFactory(ActiveMQXAConnectionFactory.class); return wrapper.wrapConnectionFactory(connectionFactory); } @@ -61,8 +59,7 @@ class ActiveMQXAConnectionFactoryConfiguration { matchIfMissing = true) ActiveMQConnectionFactory nonXaJmsConnectionFactory(ActiveMQProperties properties, ObjectProvider factoryCustomizers) { - return new ActiveMQConnectionFactoryFactory(properties, - factoryCustomizers.orderedStream().collect(Collectors.toList())) + return new ActiveMQConnectionFactoryFactory(properties, factoryCustomizers.orderedStream().toList()) .createConnectionFactory(ActiveMQConnectionFactory.class); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/ResolvedDependencies.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/ResolvedDependencies.java index 8245e2eab1..6055bd0680 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/ResolvedDependencies.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/ResolvedDependencies.java @@ -84,10 +84,10 @@ class ResolvedDependencies { } void resolvedArtifacts(Provider> resolvedArtifacts) { - this.artifactFiles.addAll(resolvedArtifacts - .map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getFile).collect(Collectors.toList()))); - this.artifactIds.addAll(resolvedArtifacts - .map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getId).collect(Collectors.toList()))); + this.artifactFiles.addAll( + resolvedArtifacts.map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getFile).toList())); + this.artifactIds.addAll( + resolvedArtifacts.map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getId).toList())); } DependencyDescriptor find(File file) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporter.java b/spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporter.java index 231c51e354..85603a7bb0 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporter.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationReporter.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Predicate; -import java.util.stream.Collectors; import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty; import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository; @@ -82,9 +81,7 @@ class PropertiesMigrationReporter { private PropertySource mapPropertiesWithReplacement(PropertiesMigrationReport report, String name, List properties) { report.add(name, properties); - List renamed = properties.stream() - .filter(PropertyMigration::isCompatibleType) - .collect(Collectors.toList()); + List renamed = properties.stream().filter(PropertyMigration::isCompatibleType).toList(); if (renamed.isEmpty()) { return null; } @@ -118,10 +115,7 @@ class PropertiesMigrationReporter { private Map> getMatchingProperties( Predicate filter) { MultiValueMap result = new LinkedMultiValueMap<>(); - List candidates = this.allProperties.values() - .stream() - .filter(filter) - .collect(Collectors.toList()); + List candidates = this.allProperties.values().stream().filter(filter).toList(); getPropertySourcesAsMap().forEach((propertySourceName, propertySource) -> candidates.forEach((metadata) -> { ConfigurationPropertyName metadataName = ConfigurationPropertyName.isValid(metadata.getId()) ? ConfigurationPropertyName.of(metadata.getId()) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java index fdd5f0c915..b32890d790 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java @@ -33,7 +33,6 @@ import java.util.Set; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; @@ -97,7 +96,7 @@ final class ModifiedClassPathClassLoader extends URLClassLoader { candidates.addAll(getAnnotatedElements(arguments.toArray())); List annotatedElements = candidates.stream() .filter(ModifiedClassPathClassLoader::hasAnnotation) - .collect(Collectors.toList()); + .toList(); if (annotatedElements.isEmpty()) { return null; }