Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6e17e82
Migrate away from Collections.singleton
epugh Mar 9, 2026
8eb1bdf
Migrate
epugh Mar 9, 2026
0333f47
Merge remote-tracking branch 'upstream/main' into SOLR-18164
epugh Mar 17, 2026
c034cd3
Merge branch 'main' into SOLR-18164
epugh Mar 17, 2026
33ccd92
Initial plan
Copilot Mar 19, 2026
854a847
Replace Collections.singletonList/singletonMap with List.of/Map.of
Copilot Mar 19, 2026
70e07c3
Revert First/LastFieldValueUpdateProcessorFactory to singletonList
Copilot Mar 19, 2026
78fe3ef
Add singletonList and singletonMap to forbidden-apis rules
Copilot Mar 19, 2026
0f852cf
Fix compilation issues: ConfigSetAdminRequest inner List class confli…
Copilot Mar 19, 2026
79c77ff
Replace Collections.singletonList/singletonMap with List.of/Map.of
Copilot Mar 19, 2026
3f37d7a
Revert First/LastFieldValueUpdateProcessorFactory to singletonList
Copilot Mar 19, 2026
a9c7206
Add singletonList and singletonMap to forbidden-apis rules
Copilot Mar 19, 2026
35af630
Fix compilation issues: ConfigSetAdminRequest inner List class confli…
Copilot Mar 19, 2026
4011ce5
Merge remote-tracking branch 'upstream/main' into SOLR-18164
epugh Mar 23, 2026
cf3fea4
Fix SchemaHandler NPE: guard Map.of with null check on pathParam
Copilot Mar 23, 2026
16ddf74
Fix NPE in Aliases.cloneWithCollectionAliasProperties when properties…
Copilot Mar 23, 2026
29a8693
Merge branch 'copilot/solr-18164-replace-singleton-calls' into SOLR-1…
epugh Mar 23, 2026
93c7fb4
Respond to feedback about when null is okay
epugh Mar 25, 2026
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
9 changes: 9 additions & 0 deletions gradle/validation/forbidden-apis/defaults.all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ java.util.Collections#emptySet()
@defaultMessage Use Map.of()
java.util.Collections#emptyMap()

@defaultMessage Use Set.of()
java.util.Collections#singleton(**)

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

@defaultMessage Use Map.of()
java.util.Collections#singletonMap(**)

java.util.Locale#forLanguageTag(java.lang.String) @ use new Locale.Builder().setLanguageTag(...).build() which has error handling
java.util.Locale#toString() @ use Locale#toLanguageTag() for a standardized BCP47 locale name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.solr.bench.generators;

import java.util.Collections;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collector;
Expand Down Expand Up @@ -105,6 +104,6 @@ private static <K, V> AsString<Map<K, V>> mapDescriber(
* @return the map . entry
*/
static <K, V> Map.Entry<K, V> mapEntry(K k, V v) {
return Collections.singletonMap(k, v).entrySet().iterator().next();
return Map.of(k, v).entrySet().iterator().next();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static org.apache.solr.bench.generators.SourceDSL.strings;

import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.request.QueryRequest;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void test() throws Exception {
true,
1,
new int[] {1},
Collections.singletonList("label"),
List.of("label"),
0,
0,
new IterationParams(IterationType.WARMUP, 1, TimeValue.milliseconds(10), 1),
Expand All @@ -71,7 +71,7 @@ public void test() throws Exception {
TimeUnit.SECONDS,
1,
"jvm",
Collections.singletonList("jvmArg"),
List.of("jvmArg"),
"jdkVersion",
"vmName",
"vmVersion",
Expand Down
13 changes: 5 additions & 8 deletions solr/core/src/java/org/apache/solr/api/AnnotatedApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -130,15 +129,15 @@ public static List<Api> getApis(Class<?> theClass, Object obj, boolean allowEmpt
throw new RuntimeException("No method with @Command in class: " + klas.getName());
}
SpecProvider specProvider = readSpec(endPoint, methods);
return Collections.singletonList(new AnnotatedApi(specProvider, endPoint, commands, null));
return List.of(new AnnotatedApi(specProvider, endPoint, commands, null));
} else {
List<Api> apis = new ArrayList<>();
for (Method m : klas.getMethods()) {
EndPoint endPoint = m.getAnnotation(EndPoint.class);
if (endPoint == null) continue;
Cmd cmd = new Cmd("", obj, m);
SpecProvider specProvider = readSpec(endPoint, Collections.singletonList(m));
apis.add(new AnnotatedApi(specProvider, endPoint, Collections.singletonMap("", cmd), null));
SpecProvider specProvider = readSpec(endPoint, List.of(m));
apis.add(new AnnotatedApi(specProvider, endPoint, Map.of("", cmd), null));
}
if (!allowEmpty && apis.isEmpty()) {
throw new RuntimeException("Invalid Class : " + klas.getName() + " No @EndPoints");
Expand Down Expand Up @@ -170,9 +169,7 @@ private static SpecProvider readSpec(EndPoint endPoint, List<Method> m) {
methods.add(method.name());
}
map.put("methods", methods);
map.put(
"url",
new ValidatingJsonMap(Collections.singletonMap("paths", Arrays.asList(endPoint.path()))));
map.put("url", new ValidatingJsonMap(Map.of("paths", Arrays.asList(endPoint.path()))));
Map<String, Object> cmds = new HashMap<>();

for (Method method : m) {
Expand Down Expand Up @@ -359,7 +356,7 @@ private void checkForErrorInPayload(CommandOperation cmd) {
throw new SolrErrorWrappingException(
SolrException.ErrorCode.BAD_REQUEST,
"Error executing command",
CommandOperation.captureErrors(Collections.singletonList(cmd)));
CommandOperation.captureErrors(List.of(cmd)));
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions solr/core/src/java/org/apache/solr/api/ApiBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -276,9 +275,9 @@ public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
if (commands != null) {
ValidatingJsonMap m = commands.getMap(cmd, null);
if (m == null) {
specCopy.put("commands", Collections.singletonMap(cmd, "Command not found!"));
specCopy.put("commands", Map.of(cmd, "Command not found!"));
} else {
specCopy.put("commands", Collections.singletonMap(cmd, m));
specCopy.put("commands", Map.of(cmd, m));
}
}
result = specCopy;
Expand Down Expand Up @@ -386,7 +385,7 @@ public static List<Api> wrapRequestHandlers(final SolrRequestHandler rh, String.
final ValidatingJsonMap spec = new ValidatingJsonMap();
spec.put("methods", List.of("GET", "POST"));
final ValidatingJsonMap urlMap = new ValidatingJsonMap();
urlMap.put("paths", Collections.singletonList("$" + HANDLER_NAME));
urlMap.put("paths", List.of("$" + HANDLER_NAME));
spec.put("url", urlMap);
return spec;
};
Expand All @@ -398,7 +397,7 @@ public PathTrie<Api> getRegistry(String method) {
public void registerLazy(PluginBag.PluginHolder<SolrRequestHandler> holder, PluginInfo info) {
register(
new LazyLoadedApi(HANDLER_NAME_SPEC_PROVIDER, holder),
Collections.singletonMap(HANDLER_NAME, info.attributes.get(NAME)));
Map.of(HANDLER_NAME, info.attributes.get(NAME)));
}

public static SpecProvider constructSpec(PluginInfo info) {
Expand All @@ -417,8 +416,7 @@ public static List<CommandOperation> getCommandOperations(
ContentStream stream, Map<String, JsonSchemaValidator> validators, boolean validate) {
List<CommandOperation> parsedCommands = null;
try {
parsedCommands =
CommandOperation.readCommands(Collections.singleton(stream), new NamedList<>());
parsedCommands = CommandOperation.readCommands(Set.of(stream), new NamedList<>());
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to parse commands", e);
}
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/cli/CLIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -278,7 +278,7 @@ public static CloudSolrClient getCloudSolrClient(String zkHost) {

public static CloudSolrClient getCloudSolrClient(
String zkHost, HttpJettySolrClient.Builder builder) {
return new CloudSolrClient.Builder(Collections.singletonList(zkHost), Optional.empty())
return new CloudSolrClient.Builder(List.of(zkHost), Optional.empty())
.withHttpClientBuilder(builder)
.build();
}
Expand Down
5 changes: 1 addition & 4 deletions solr/core/src/java/org/apache/solr/cli/ExportTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -247,9 +246,7 @@ void fetchUniqueKey() throws SolrServerException, IOException {
var builder = new HttpJettySolrClient.Builder().withOptionalBasicAuthCredentials(credentials);

solrClient =
new CloudSolrClient.Builder(Collections.singletonList(baseurl))
.withHttpClientBuilder(builder)
.build();
new CloudSolrClient.Builder(List.of(baseurl)).withHttpClientBuilder(builder).build();
NamedList<Object> response =
solrClient.request(
new GenericSolrRequest(
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/cli/RunExampleTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import java.nio.file.StandardCopyOption;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -674,7 +674,7 @@ protected void runCloudExample(CommandLine cli) throws Exception {
/** wait until the number of live nodes == numNodes. */
protected void waitToSeeLiveNodes(String zkHost, int numNodes) {
try (CloudSolrClient cloudClient =
new CloudSolrClient.Builder(Collections.singletonList(zkHost), Optional.empty()).build()) {
new CloudSolrClient.Builder(List.of(zkHost), Optional.empty()).build()) {
Set<String> liveNodes = cloudClient.getClusterState().getLiveNodes();
int numLiveNodes = (liveNodes != null) ? liveNodes.size() : 0;
long timeoutNanos = System.nanoTime() + TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@

package org.apache.solr.cloud;

import static java.util.Collections.singletonMap;
import static org.apache.solr.cloud.overseer.ZkStateWriter.NO_OP;
import static org.apache.solr.common.cloud.ZkStateReader.COLLECTIONS_ZKNODE;

import java.lang.invoke.MethodHandles;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -548,7 +546,7 @@ private void doStateDotJsonCasUpdate(ClusterState updatedState)
} else {
// Collection update or creation
DocCollection collection = updatedState.getCollection(updater.getCollectionName());
byte[] stateJson = Utils.toJSON(singletonMap(updater.getCollectionName(), collection));
byte[] stateJson = Utils.toJSON(Map.of(updater.getCollectionName(), collection));

if (updater.isCollectionCreation()) {
// The state.json file does not exist yet (more precisely it is assumed not to exist)
Expand Down Expand Up @@ -946,10 +944,7 @@ public void computeUpdates(ClusterState clusterState, SolrZkClient client) {
(zkcmd != ZkStateWriter.NO_OP)
? clusterState.copyWith(zkcmd.name, zkcmd.collection)
: null;
replicaOpsList =
(zkcmd.ops != null && zkcmd.ops.get() != null)
? Collections.singletonList(zkcmd.ops)
: null;
replicaOpsList = (zkcmd.ops != null && zkcmd.ops.get() != null) ? List.of(zkcmd.ops) : null;
} else {
computedState = null;
replicaOpsList = null;
Expand Down
34 changes: 16 additions & 18 deletions solr/core/src/java/org/apache/solr/cloud/Overseer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -510,40 +509,39 @@ private List<ZkWriteCommand> processMessage(
if (collectionAction != null) {
switch (collectionAction) {
case CREATE:
return Collections.singletonList(
return List.of(
new ClusterStateMutator(getSolrCloudManager())
.createCollection(clusterState, message));
case DELETE:
return Collections.singletonList(
return List.of(
new ClusterStateMutator(getSolrCloudManager())
.deleteCollection(clusterState, message));
case CREATESHARD:
return Collections.singletonList(
return List.of(
new CollectionMutator(getSolrCloudManager()).createShard(clusterState, message));
case DELETESHARD:
return Collections.singletonList(
return List.of(
new CollectionMutator(getSolrCloudManager()).deleteShard(clusterState, message));
case ADDREPLICA:
return Collections.singletonList(
return List.of(
new SliceMutator(getSolrCloudManager()).addReplica(clusterState, message));
case ADDREPLICAPROP:
return Collections.singletonList(
return List.of(
new ReplicaMutator(getSolrCloudManager())
.addReplicaProperty(clusterState, message));
case DELETEREPLICAPROP:
return Collections.singletonList(
return List.of(
new ReplicaMutator(getSolrCloudManager())
.deleteReplicaProperty(clusterState, message));
case BALANCESHARDUNIQUE:
ExclusiveSliceProperty dProp = new ExclusiveSliceProperty(clusterState, message);
if (dProp.balanceProperty()) {
String collName = message.getStr(ZkStateReader.COLLECTION_PROP);
return Collections.singletonList(
new ZkWriteCommand(collName, dProp.getDocCollection()));
return List.of(new ZkWriteCommand(collName, dProp.getDocCollection()));
}
break;
case MODIFYCOLLECTION:
return Collections.singletonList(
return List.of(
new CollectionMutator(getSolrCloudManager())
.modifyCollection(clusterState, message));
default:
Expand All @@ -558,22 +556,22 @@ private List<ZkWriteCommand> processMessage(
}
switch (overseerAction) {
case STATE:
return Collections.singletonList(
return List.of(
new ReplicaMutator(getSolrCloudManager()).setState(clusterState, message));
case LEADER:
return Collections.singletonList(
return List.of(
new SliceMutator(getSolrCloudManager()).setShardLeader(clusterState, message));
case DELETECORE:
return Collections.singletonList(
return List.of(
new SliceMutator(getSolrCloudManager()).removeReplica(clusterState, message));
case ADDROUTINGRULE:
return Collections.singletonList(
return List.of(
new SliceMutator(getSolrCloudManager()).addRoutingRule(clusterState, message));
case REMOVEROUTINGRULE:
return Collections.singletonList(
return List.of(
new SliceMutator(getSolrCloudManager()).removeRoutingRule(clusterState, message));
case UPDATESHARDSTATE:
return Collections.singletonList(
return List.of(
new SliceMutator(getSolrCloudManager()).updateShardState(clusterState, message));
case QUIT:
if (myId.equals(message.get(ID))) {
Expand All @@ -594,7 +592,7 @@ private List<ZkWriteCommand> processMessage(
}
}

return Collections.singletonList(ZkStateWriter.NO_OP);
return List.of(ZkStateWriter.NO_OP);
}

private LeaderStatus amILeader() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
Expand Down Expand Up @@ -287,7 +287,7 @@ private ModifiableSolrParams getReplicaParams(
ccc.getZkStateReader(),
ccc.getSolrCloudManager().getTimeSource(),
collectionName,
Collections.singleton(createReplica.coreName))
Set.of(createReplica.coreName))
.get(createReplica.coreName)
.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static List<ReplicaPosition> getNodesForNewReplicas(
AssignRequest assignRequest =
new AssignRequestBuilder()
.forCollection(collectionName)
.forShard(Collections.singletonList(shard))
.forShard(List.of(shard))
.assignReplicas(numReplicas)
.onNodes(createNodeList)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ static void cleanBackup(
BackupRepository repository, URI backupUri, BackupId backupId, CollectionCommandContext ccc)
throws Exception {
new DeleteBackupCmd(ccc)
.deleteBackupIds(backupUri, repository, Collections.singleton(backupId), new NamedList<>());
.deleteBackupIds(backupUri, repository, Set.of(backupId), new NamedList<>());
}

static void deleteBackup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;

import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -179,8 +178,7 @@ private void ensureAliasCollection(
// Create the collection
createCollectionAndWait(
adminCmdContext, aliasName, aliasProperties, initialCollectionName, ccc);
validateAllCollectionsExistAndNoDuplicates(
Collections.singletonList(initialCollectionName), zkStateReader);
validateAllCollectionsExistAndNoDuplicates(List.of(initialCollectionName), zkStateReader);
}

private void validateAllCollectionsExistAndNoDuplicates(
Expand Down
Loading
Loading