Skip to content

Commit 601f741

Browse files
epughCopilot
andauthored
SOLR-18139: Migrate away from Collections.empty*() methods. (#4168)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0259ab2 commit 601f741

256 files changed

Lines changed: 543 additions & 772 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build-tools/missing-doclet/src/main/java/org/apache/lucene/missingdoclet/MissingDoclet.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.List;
2626
import java.util.Locale;
2727
import java.util.Set;
28-
import java.util.stream.Collectors;
2928
import java.util.stream.Stream;
3029
import javax.lang.model.element.Element;
3130
import javax.lang.model.element.ElementKind;
@@ -65,8 +64,8 @@ public class MissingDoclet extends StandardDoclet {
6564
DocletEnvironment docEnv;
6665
DocTrees docTrees;
6766
Elements elementUtils;
68-
Set<String> ignored = Collections.emptySet();
69-
Set<String> methodPackages = Collections.emptySet();
67+
Set<String> ignored = Set.of();
68+
Set<String> methodPackages = Set.of();
7069

7170
@Override
7271
public Set<Doclet.Option> getSupportedOptions() {
@@ -373,7 +372,7 @@ private Stream<Element> superTypeForInheritDoc(Element type) {
373372
clazz.getInterfaces().stream()
374373
.filter(tm -> tm.getKind() == TypeKind.DECLARED)
375374
.map(tm -> ((DeclaredType) tm).asElement())
376-
.collect(Collectors.toList());
375+
.toList();
377376

378377
Stream<Element> result = interfaces.stream();
379378
result = Stream.concat(result, interfaces.stream().flatMap(this::superTypeForInheritDoc));

gradle/validation/forbidden-apis/defaults.all.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ java.io.File#delete() @ use Files.delete for real exception, IOUtils.deleteFiles
5454

5555
java.util.Collections#shuffle(java.util.List) @ Use shuffle(List, Random) instead so that it can be reproduced
5656

57+
@defaultMessage Use List.of()
58+
java.util.Collections#emptyList()
59+
60+
@defaultMessage Use Set.of()
61+
java.util.Collections#emptySet()
62+
63+
@defaultMessage Use Map.of()
64+
java.util.Collections#emptyMap()
65+
5766
java.util.Locale#forLanguageTag(java.lang.String) @ use new Locale.Builder().setLanguageTag(...).build() which has error handling
5867
java.util.Locale#toString() @ use Locale#toLanguageTag() for a standardized BCP47 locale name
5968

@@ -102,4 +111,4 @@ java.nio.file.Paths#get(**)
102111
java.nio.file.Path#startsWith(java.lang.String)
103112

104113
@defaultMessage Use NIO Path instead of File
105-
java.io.File
114+
java.io.File

solr/benchmark/src/java/org/apache/solr/bench/generators/RandomDataHistogram.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.math.RoundingMode;
2424
import java.util.ArrayList;
2525
import java.util.Collection;
26-
import java.util.Collections;
2726
import java.util.Comparator;
2827
import java.util.List;
2928
import java.util.Locale;
@@ -509,7 +508,7 @@ public String print(boolean sortByLabel, int bucketed) {
509508
}
510509
return Integer.compare(e2.getValue().get(), e1.getValue().get());
511510
})
512-
.filter(entry -> !entry.getKey().equals(Collections.emptyList()))
511+
.filter(entry -> !entry.getKey().equals(List.of()))
513512
.map(
514513
entry -> {
515514
double percentage = entry.getValue().get() * 100.0 / sum;

solr/core/src/java/org/apache/solr/api/ApiBag.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ public ApiBag(boolean isCoreSpecific) {
7575
public synchronized List<Api> registerObject(Object o) {
7676
List<Api> l = AnnotatedApi.getApis(o);
7777
for (Api api : l) {
78-
register(api, Collections.emptyMap());
78+
register(api, Map.of());
7979
}
8080
return l;
8181
}
8282

8383
public synchronized void register(Api api) {
84-
register(api, Collections.emptyMap());
84+
register(api, Map.of());
8585
}
8686

8787
public synchronized void register(Api api, Map<String, String> nameSubstitutes) {

solr/core/src/java/org/apache/solr/api/ApiSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.solr.api;
1919

2020
import java.util.Collection;
21-
import java.util.Collections;
21+
import java.util.Set;
2222

2323
/** The interface that is implemented by a request handler to support the V2 end point */
2424
public interface ApiSupport {
@@ -36,7 +36,7 @@ public interface ApiSupport {
3636
* @see #getApis()
3737
*/
3838
default Collection<Class<? extends JerseyResource>> getJerseyResources() {
39-
return Collections.emptySet();
39+
return Set.of();
4040
}
4141

4242
/** Whether this should be made available at the regular legacy path */

solr/core/src/java/org/apache/solr/api/ContainerPluginsRegistry.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.lang.reflect.ParameterizedType;
3232
import java.lang.reflect.Type;
3333
import java.util.ArrayList;
34-
import java.util.Collections;
3534
import java.util.HashMap;
3635
import java.util.List;
3736
import java.util.Map;
@@ -424,7 +423,7 @@ public void init() throws Exception {
424423
throw new RuntimeException("Must have a no-arg constructor or CoreContainer constructor ");
425424
}
426425
Map<String, Object> config =
427-
(Map<String, Object>) holder.original.getOrDefault("config", Collections.emptyMap());
426+
(Map<String, Object>) holder.original.getOrDefault("config", Map.of());
428427
configure(instance, config, holder.meta);
429428
if (instance instanceof ResourceLoaderAware) {
430429
try {

solr/core/src/java/org/apache/solr/api/V2HttpCall.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.io.IOException;
3030
import java.lang.invoke.MethodHandles;
3131
import java.util.ArrayList;
32-
import java.util.Collections;
3332
import java.util.HashMap;
3433
import java.util.HashSet;
3534
import java.util.LinkedHashMap;
@@ -488,7 +487,7 @@ private String computeEndpointPath() {
488487
// myColName -> collection
489488
final Map<String, String> pathTemplateValKey;
490489
if (pathTemplateKeyVal.isEmpty()) { // typical
491-
pathTemplateValKey = Collections.emptyMap();
490+
pathTemplateValKey = Map.of();
492491
} else if (pathTemplateKeyVal.size() == 1) { // typical
493492
Map.Entry<String, String> entry = pathTemplateKeyVal.entrySet().iterator().next();
494493
pathTemplateValKey = Map.of(entry.getValue(), entry.getKey());

solr/core/src/java/org/apache/solr/cloud/CloudUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.io.IOException;
2020
import java.lang.invoke.MethodHandles;
21-
import java.util.Collections;
2221
import java.util.HashMap;
2322
import java.util.List;
2423
import java.util.Map;
@@ -136,7 +135,7 @@ public static Map<String, byte[]> getTrustedKeys(SolrZkClient zk, String dir) {
136135
}
137136
} catch (KeeperException.NoNodeException e) {
138137
log.info("Error fetching key names");
139-
return Collections.emptyMap();
138+
return Map.of();
140139
} catch (InterruptedException e) {
141140
Thread.currentThread().interrupt();
142141
throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to read crypto keys", e);

solr/core/src/java/org/apache/solr/cloud/DistributedClusterStateUpdater.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.ArrayList;
2727
import java.util.Collections;
2828
import java.util.List;
29+
import java.util.Map;
2930
import java.util.Optional;
3031
import java.util.Set;
3132
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
@@ -387,7 +388,7 @@ private void applyUpdate() throws KeeperException, InterruptedException {
387388
// For now trying to diverge as little as possible from existing data structures and code
388389
// given the need to support both the old way (Overseer) and new way (distributed) of handling
389390
// cluster state update.
390-
final Set<String> liveNodes = Collections.emptySet();
391+
final Set<String> liveNodes = Set.of();
391392

392393
// Per Replica States updates are done before all other updates and not subject to the number
393394
// of attempts of CAS made here, given they have their own CAS strategy and implementation
@@ -412,7 +413,7 @@ private void applyUpdate() throws KeeperException, InterruptedException {
412413
// state. Knowing about all collections in the cluster might not be needed.
413414
ClusterState initialClusterState;
414415
if (updater.isCollectionCreation()) {
415-
initialClusterState = new ClusterState(liveNodes, Collections.emptyMap());
416+
initialClusterState = new ClusterState(liveNodes, Map.of());
416417
} else {
417418
// Get the state for existing data in ZK (and if no data exists we should fail)
418419
initialClusterState = fetchStateForCollection();
@@ -586,7 +587,7 @@ private ClusterState fetchStateForCollection() throws KeeperException, Interrupt
586587
ZkClientClusterStateProvider.createFromJsonSupportingLegacyConfigName(
587588
stat.getVersion(),
588589
data,
589-
Collections.emptySet(),
590+
Set.of(),
590591
updater.getCollectionName(),
591592
zkStateReader.getZkClient(),
592593
Instant.ofEpochMilli(stat.getCtime()));

solr/core/src/java/org/apache/solr/cloud/ZkConfigSetService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public Map<String, Object> getConfigMetadata(String configName) throws IOExcepti
234234
Utils.fromJSON(zkClient.getData(CONFIGS_ZKNODE + "/" + configName, null, null));
235235
return data;
236236
} catch (KeeperException.NoNodeException e) {
237-
return Collections.emptyMap();
237+
return Map.of();
238238
} catch (KeeperException | InterruptedException e) {
239239
throw new IOException("Error getting config metadata", SolrZkClient.checkInterrupted(e));
240240
}
@@ -261,7 +261,7 @@ public List<String> listConfigs() throws IOException {
261261
try {
262262
return zkClient.getChildren(CONFIGS_ZKNODE, null);
263263
} catch (KeeperException.NoNodeException e) {
264-
return Collections.emptyList();
264+
return List.of();
265265
} catch (KeeperException | InterruptedException e) {
266266
throw new IOException("Error listing configs", SolrZkClient.checkInterrupted(e));
267267
}

0 commit comments

Comments
 (0)