Add checkstyle rule for List.of() / Set.of() / Map.of()

This commits adds a checkstyle rule to not use List.of(), Set.of()
and Map.of(), preferring Collections.emptyList(), emptySet(), and
emptyMap() respectively.

It replaces usages of these methods across the codebase.

See gh-32655
This commit is contained in:
Bertolt Meier
2022-10-10 12:35:32 +02:00
committed by Andy Wilkinson
parent 7626de4e91
commit 647a2905c8
10 changed files with 34 additions and 15 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.kafka;
import java.util.Collections;
import java.util.Map;
import org.apache.kafka.common.config.SslConfigs;
@@ -55,7 +56,7 @@ class KafkaPropertiesTests {
@Test
void adminDefaultValuesAreConsistent() {
KafkaAdmin admin = new KafkaAdmin(Map.of());
KafkaAdmin admin = new KafkaAdmin(Collections.emptyMap());
Admin adminProperties = new KafkaProperties().getAdmin();
assertThat(admin).hasFieldOrPropertyWithValue("fatalIfBrokerNotAvailable", adminProperties.isFailFast());
assertThat(admin).hasFieldOrPropertyWithValue("modifyTopicConfigs", adminProperties.isModifyTopicConfigs());

View File

@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.web;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
@@ -52,7 +53,7 @@ class WebResourcesRuntimeHintsTests {
@Test
void registerHintsWithNoLocation() {
RuntimeHints hints = register(new TestClassLoader(List.of()));
RuntimeHints hints = register(new TestClassLoader(Collections.emptyList()));
assertThat(hints.resources().resourcePatternHints()).isEmpty();
}