Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gradle/validation/forbidden-apis/java.solr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ java.util.LinkedHashMap#<init>(int)

@defaultMessage Use CollectionUtil.newHashSet(int)
java.util.HashSet#<init>(int)

@defaultMessage Use List.of()
java.util.Collections#emptyList()

Copilot AI Feb 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collections.emptyList() is now forbidden, but there are still remaining call sites using the generic form Collections.<T>emptyList() (e.g., solr/core/src/test/org/apache/solr/legacy/TestLegacyNumericUtils.java around the inverse-range assertions). With this forbidden-apis rule enabled, those remaining usages will fail the build; please migrate them to List.of() (or another appropriate empty list) as part of this PR.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, so turns out this needs to be in defaults.all.txt.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -509,7 +508,7 @@ public String print(boolean sortByLabel, int bucketed) {
}
return Integer.compare(e2.getValue().get(), e1.getValue().get());
})
.filter(entry -> !entry.getKey().equals(Collections.emptyList()))
.filter(entry -> !entry.getKey().equals(List.of()))
.map(
entry -> {
double percentage = entry.getValue().get() * 100.0 / sum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public List<String> listConfigs() throws IOException {
try {
return zkClient.getChildren(CONFIGS_ZKNODE, null);
} catch (KeeperException.NoNodeException e) {
return Collections.emptyList();
return List.of();
} catch (KeeperException | InterruptedException e) {
throw new IOException("Error listing configs", SolrZkClient.checkInterrupted(e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -260,7 +259,7 @@ protected List<Action> calculateActions(String targetCol) {
}
return actionList;
} else {
return Collections.emptyList();
return List.of();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ private CandidateCollection calcCandidateCollection(Instant docTimestamp) {
private List<Action> calcDeletes(List<Action> actions) {
final String autoDeleteAgeMathStr = this.getAutoDeleteAgeMath();
if (autoDeleteAgeMathStr == null || actions.size() == 0) {
return Collections.emptyList();
return List.of();
}
if (actions.size() > 1) {
throw new IllegalStateException(
Expand Down Expand Up @@ -675,7 +675,7 @@ private List<Action> calcAdd(String targetCol) {
String nextCol = calcNextCollection(parsed);
return Collections.singletonList(new Action(this, ActionType.ENSURE_EXISTS, nextCol));
} else {
return Collections.emptyList();
return List.of();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ public Collection<Replica.ReplicaType> getOutstandingReplicaTypes(String shard)
.map(Map::keySet)
// Use a sorted TreeSet to make sure that tests are repeatable
.<Collection<Replica.ReplicaType>>map(TreeSet::new)
.orElseGet(Collections::emptyList);
.orElseGet(List::of);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions solr/core/src/java/org/apache/solr/core/CoreSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.solr.core;

import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;

import java.util.Collection;
Expand Down Expand Up @@ -47,7 +46,7 @@ public class CoreSorter {
if (c1 == null) c1 = zero; // just to avoid NPE
if (c2 == null) c2 = zero;
if (c1.totalReplicasInDownNodes < c2.totalReplicasInDownNodes) {
// Prioritize replicas with least no:of down nodes waiting.
// Prioritize replicas with the least number of down nodes waiting.
// It's better to bring up a node that is a member of a shard
// with 0 down nodes than 1 down node because it will make the shard
// complete earlier and avoid waiting by the other live nodes
Expand All @@ -64,7 +63,7 @@ public class CoreSorter {
}
}

// Prioritize replicas where most no:of other nodes are waiting for
// Prioritize replicas where the greatest number of other nodes waiting.
// For example if 1 other replicas are waiting for this replica, then
// prioritize that over the replica were zero other nodes are waiting
Comment thread
epugh marked this conversation as resolved.
Outdated
if (c1.totalReplicasInLiveNodes > c2.totalReplicasInLiveNodes) return -1;
Expand Down Expand Up @@ -176,9 +175,9 @@ private static String getShardName(CloudDescriptor cd) {
/** Return all replicas for a given collection+slice combo */
private Collection<Replica> getReplicas(ClusterState cs, String coll, String slice) {
DocCollection c = cs.getCollectionOrNull(coll);
if (c == null) return emptyList();
if (c == null) return List.of();
Slice s = c.getSlice(slice);
if (s == null) return emptyList();
if (s == null) return List.of();
return s.getReplicas();
}
}
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/core/NodeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ public static class NodeConfigBuilder {
private PluginInfo[] clusterPlugins;
private String defaultZkHost;
private Set<Path> allowPaths = Collections.emptySet();
private List<String> allowUrls = Collections.emptyList();
private List<String> allowUrls = List.of();
private boolean hideStackTrace =
!EnvUtils.getPropertyAsBool("solr.responses.stacktrace.enabled", true);

Expand Down
8 changes: 4 additions & 4 deletions solr/core/src/java/org/apache/solr/core/PluginInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public PluginInfo(
}
}
attributes = unmodifiableMap(attrs);
this.children = children == null ? Collections.emptyList() : unmodifiableList(children);
this.children = children == null ? List.of() : unmodifiableList(children);
isFromSolrConfig = false;
}

Expand Down Expand Up @@ -148,7 +148,7 @@ public PluginInfo(String type, Map<String, Object> map) {
// TODO This is not type-safe and needs to be fixed -
// https://issues.apache.org/jira/browse/SOLR-14696
attributes = unmodifiableMap(m);
this.children = Collections.emptyList();
this.children = List.of();
isFromSolrConfig = true;
}

Expand All @@ -162,7 +162,7 @@ private List<PluginInfo> loadSubPlugins(ConfigNode node) {
if (pluginInfo.isEnabled()) children.add(pluginInfo);
return null;
});
return children.isEmpty() ? Collections.emptyList() : unmodifiableList(children);
return children.isEmpty() ? List.of() : unmodifiableList(children);
}

@Override
Expand Down Expand Up @@ -230,7 +230,7 @@ public List<PluginInfo> getChildren(String type) {
}

public static final PluginInfo EMPTY_INFO =
new PluginInfo("", Collections.emptyMap(), new NamedList<>(), Collections.emptyList());
new PluginInfo("", Collections.emptyMap(), new NamedList<>(), List.of());

private static final HashSet<String> NL_TAGS =
new HashSet<>(asList("lst", "arr", "bool", "str", "int", "long", "float", "double"));
Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/core/SolrConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ public List<PluginInfo> getPluginInfos(String type) {
result = new ArrayList<>(map.values());
}
}
return result == null ? Collections.emptyList() : result;
return result == null ? List.of() : result;
}

public PluginInfo getPluginInfo(String type) {
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/core/SolrCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -3231,7 +3231,7 @@ public void initDefaultPlugin(Object plugin, Class<?> type) {
* @return The instances initialized
*/
public <T> List<T> initPlugins(List<PluginInfo> pluginInfos, Class<T> type, String defClassName) {
if (pluginInfos.isEmpty()) return Collections.emptyList();
if (pluginInfos.isEmpty()) return List.of();
List<T> result = new ArrayList<>(pluginInfos.size());
for (PluginInfo info : pluginInfos)
result.add(createInitInstance(info, type, type.getSimpleName(), defClassName));
Expand Down Expand Up @@ -3623,7 +3623,7 @@ private ImplicitPluginsHolder() {}
}

public static List<PluginInfo> getImplicitPlugins(String type) {
return ALL_IMPLICIT_PLUGINS.getOrDefault(type, Collections.emptyList());
return ALL_IMPLICIT_PLUGINS.getOrDefault(type, List.of());
}
}

Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private static NodeConfig fillSolrSection(NodeConfig.NodeConfigBuilder builder,

private static List<String> separateStrings(String commaSeparatedString) {
if (StrUtils.isNullOrEmpty(commaSeparatedString)) {
return Collections.emptyList();
return List.of();
}
return Arrays.asList(COMMA_SEPARATED_PATTERN.split(commaSeparatedString));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -125,8 +124,7 @@ public static enum SnapshotStatus {
private final List<CoreSnapshotMetaData> replicaSnapshots;

public CollectionSnapshotMetaData(String name) {
this(
name, SnapshotStatus.InProgress, new Date(), Collections.<CoreSnapshotMetaData>emptyList());
this(name, SnapshotStatus.InProgress, new Date(), List.of());
}

public CollectionSnapshotMetaData(
Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/handler/ClusterAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public static List<String> getNodesByRole(
try {
return zk.listData(ZkStateReader.NODE_ROLES + "/" + role + "/" + mode);
} catch (NoSuchElementException e) {
return Collections.emptyList();
return List.of();
}
}

Expand Down
17 changes: 8 additions & 9 deletions solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private void fetchFileList(long gen) throws IOException {
List<Map<String, Object>> files = (List<Map<String, Object>>) response.get(CMD_GET_FILE_LIST);
if (files != null) filesToDownload = Collections.synchronizedList(files);
else {
filesToDownload = Collections.emptyList();
filesToDownload = List.of();
log.error("No files to download for index generation: {}", gen);
}

Expand Down Expand Up @@ -1473,7 +1473,7 @@ private List<Path> makeTmpConfDirFileList(Path dir) {
return Files.walk(dir).filter(Files::isRegularFile).collect(Collectors.toList());
} catch (IOException e) {
log.warn("Could not walk file tree", e);
return Collections.emptyList();
return List.of();
}
}

Expand Down Expand Up @@ -1532,8 +1532,7 @@ private String getDateAsStr(Date d) {
*/
private Collection<Map<String, Object>> getModifiedConfFiles(
List<Map<String, Object>> confFilesToDownload) {
if (confFilesToDownload == null || confFilesToDownload.isEmpty())
return Collections.emptyList();
if (confFilesToDownload == null || confFilesToDownload.isEmpty()) return List.of();
// build a map with alias/name as the key
Map<String, Map<String, Object>> nameVsFile = new HashMap<>();
NamedList<String> names = new NamedList<>();
Expand All @@ -1555,7 +1554,7 @@ private Collection<Map<String, Object>> getModifiedConfFiles(
nameVsFile.remove(name); // checksums are same so the file need not be downloaded
}
}
return nameVsFile.isEmpty() ? Collections.emptyList() : nameVsFile.values();
return nameVsFile.isEmpty() ? List.of() : nameVsFile.values();
}

static boolean delTree(Path dir) {
Expand Down Expand Up @@ -1600,25 +1599,25 @@ List<Map<String, Object>> getConfFilesToDownload() {
// make a copy first because it can be null later
List<Map<String, Object>> tmp = confFilesToDownload;
// create a new instance. or else iterator may fail
return tmp == null ? Collections.emptyList() : new ArrayList<>(tmp);
return tmp == null ? List.of() : new ArrayList<>(tmp);
}

List<Map<String, Object>> getConfFilesDownloaded() {
// make a copy first because it can be null later
List<Map<String, Object>> tmp = confFilesDownloaded;
// NOTE: it's safe to make a copy of a SynchronizedCollection(ArrayList)
return tmp == null ? Collections.emptyList() : new ArrayList<>(tmp);
return tmp == null ? List.of() : new ArrayList<>(tmp);
}

List<Map<String, Object>> getFilesToDownload() {
// make a copy first because it can be null later
List<Map<String, Object>> tmp = filesToDownload;
return tmp == null ? Collections.emptyList() : new ArrayList<>(tmp);
return tmp == null ? List.of() : new ArrayList<>(tmp);
}

List<Map<String, Object>> getFilesDownloaded() {
List<Map<String, Object>> tmp = filesDownloaded;
return tmp == null ? Collections.emptyList() : new ArrayList<>(tmp);
return tmp == null ? List.of() : new ArrayList<>(tmp);
}

// TODO: currently does not reflect conf files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
if (mltDocs.docSet == null) {
rsp.add("facet_counts", null);
} else {
final ResponseBuilder responseBuilder =
new ResponseBuilder(req, rsp, Collections.emptyList());
final ResponseBuilder responseBuilder = new ResponseBuilder(req, rsp, List.of());
responseBuilder.setQuery(mlt.getRealMLTQuery());
SimpleFacets f = new SimpleFacets(req, mltDocs.docSet, params, responseBuilder);
FacetComponent.FacetContext.initContext(responseBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -1410,7 +1409,6 @@ static Map<String, Object> copy(
/** Copy all params to the given map or if the given map is null create a new one */
static Map<String, Object> copy(
SolrParams source, Map<String, Object> sink, String... paramNames) {
return copy(
source, sink, paramNames == null ? Collections.emptyList() : Arrays.asList(paramNames));
return copy(source, sink, paramNames == null ? List.of() : Arrays.asList(paramNames));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -140,7 +139,7 @@ protected FileListResponse getFileList(long generation, ReplicationHandler repli
if (generation == -1) {
commit = delPol.getAndSaveLatestCommit();
if (null == commit) {
filesResponse.fileList = Collections.emptyList();
filesResponse.fileList = List.of();
return filesResponse;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private List<String> findReplicas(
if (slice == null) {
// Treat this the same as "all servers down" for a slice, and let things continue
// if partial results are acceptable
return Collections.emptyList();
return List.of();
} else {
final Predicate<Replica> isShardLeader =
new IsLeaderPredicate(
Expand Down
Loading
Loading