Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 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
782e881
Merge remote-tracking branch 'upstream/main' into SOLR-18164
epugh Apr 13, 2026
b23fb65
apply updates to recently merged upstream code
epugh Apr 13, 2026
3049c14
Merge remote-tracking branch 'upstream/main' into SOLR-18164
epugh Apr 24, 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
3 changes: 3 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,9 @@ java.util.Collections#emptySet()
@defaultMessage Use Map.of()
java.util.Collections#emptyMap()

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

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
3 changes: 1 addition & 2 deletions solr/core/src/java/org/apache/solr/api/ApiBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,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
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 @@ -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 @@ -270,7 +270,7 @@ private void deleteBackupId(
"Backup ID [" + bid + "] not found; cannot be deleted");
}

deleteBackupIds(backupPath, repository, Collections.singleton(backupId), results);
deleteBackupIds(backupPath, repository, Set.of(backupId), results);
}

static final class PurgeGraph {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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.Objects;
Expand Down Expand Up @@ -53,7 +52,7 @@ public class DeleteCollectionCmd implements CollApiCmds.CollectionApiCommand {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private static final Set<String> okayExceptions =
Collections.singleton(NonExistentCoreException.class.getName());
Set.of(NonExistentCoreException.class.getName());

private final CollectionCommandContext ccc;

Expand Down
2 changes: 1 addition & 1 deletion solr/core/src/java/org/apache/solr/core/SolrCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ private static void writeNewIndexProps(Directory dir, String tmpFileName, String
IndexOutput out = dir.createOutput(tmpFileName, DirectoryFactory.IOCONTEXT_NO_CACHE);
os = new OutputStreamWriter(new IndexOutputOutputStream(out), StandardCharsets.UTF_8);
p.store(os, IndexFetcher.INDEX_PROPERTIES);
dir.sync(Collections.singleton(tmpFileName));
dir.sync(Set.of(tmpFileName));
} catch (Exception e) {
throw new SolrException(
ErrorCode.SERVER_ERROR, "Unable to write " + IndexFetcher.INDEX_PROPERTIES, e);
Expand Down
3 changes: 1 addition & 2 deletions solr/core/src/java/org/apache/solr/core/SolrPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.lang.invoke.MethodHandles;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.exec.OS;
Expand All @@ -36,7 +35,7 @@ public final class SolrPaths {
public static final Path ALL_PATH = Path.of("_ALL_");

/** Special singleton path set containing only {@link #ALL_PATH}. */
private static final Set<Path> ALL_PATHS = Collections.singleton(ALL_PATH);
private static final Set<Path> ALL_PATHS = Set.of(ALL_PATH);

private SolrPaths() {} // don't create this

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.solr.common.util.Utils;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void store(BackupRepository repository, URI folderURI, ShardBackupId shar
final String filename = shardBackupId.getBackupMetadataFilename();
URI fileURI = repository.resolve(folderURI, filename);
if (repository.exists(fileURI)) {
repository.delete(folderURI, Collections.singleton(filename));
repository.delete(folderURI, Set.of(filename));
}

try (OutputStream os = repository.createOutput(repository.resolve(folderURI, filename))) {
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ private void logReplicationTimeAndConfFiles(
try (Writer outFile =
new OutputStreamWriter(new IndexOutputOutputStream(out), StandardCharsets.UTF_8)) {
props.store(outFile, "Replication details");
dir.sync(Collections.singleton(tmpFileName));
dir.sync(Set.of(tmpFileName));
}

solrCore.getDirectoryFactory().renameWithOverwrite(dir, tmpFileName, REPLICATION_PROPERTIES);
Expand Down Expand Up @@ -1952,7 +1952,7 @@ private static class DirectoryFile implements FileInterface {

@Override
public void sync() throws IOException {
copy2Dir.sync(Collections.singleton(saveAs));
copy2Dir.sync(Set.of(saveAs));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import net.jcip.annotations.NotThreadSafe;
import org.apache.lucene.document.Document;
Expand Down Expand Up @@ -447,7 +447,7 @@ public DocListAndSet getMoreLikeThis(
buffered.append(chunk, 0, len);
}

Collection<Object> streamValue = Collections.singleton(buffered.get().toString());
Collection<Object> streamValue = Set.of(buffered.get().toString());
Map<String, Collection<Object>> multifieldDoc = CollectionUtil.newHashMap(fields.length);
for (String field : fields) {
multifieldDoc.put(field, streamValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import org.apache.solr.api.Api;
import org.apache.solr.api.ApiBag;
import org.apache.solr.api.ApiSupport;
Expand Down Expand Up @@ -421,8 +421,7 @@ public PluginInfo getPluginInfo() {

@Override
public Collection<Api> getApis() {
return Collections.singleton(
new ApiBag.ReqHandlerToApi(this, ApiBag.constructSpec(pluginInfo)));
return Set.of(new ApiBag.ReqHandlerToApi(this, ApiBag.constructSpec(pluginInfo)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
Expand Down Expand Up @@ -78,7 +77,7 @@ public void getColStatus(NamedList<Object> results) {
if (col == null) {
collections = clusterState.getCollectionNames();
} else {
collections = Collections.singleton(col);
collections = Set.of(col);
}
boolean withFieldInfo = props.getBool(FIELD_INFO_PROP, false);
boolean withCoreInfo = props.getBool(CORE_INFO_PROP, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ protected ElevationProvider loadElevationProvider(Document doc) {
String e = DOMUtil.getAttr(child, EXCLUDE, null);
if (e != null) {
if (Boolean.valueOf(e)) {
elevationBuilder.addExcludedIds(Collections.singleton(id));
elevationBuilder.addExcludedIds(Set.of(id));
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,7 @@ private static SolrDocument mergePartialDocWithFullDocFromIndex(
searcher
.getDocFetcher()
.decorateDocValueFields(
doc,
docid,
Collections.singleton(VERSION_FIELD),
new DocValuesIteratorCache(searcher, false));
doc, docid, Set.of(VERSION_FIELD), new DocValuesIteratorCache(searcher, false));
}

long docVersion = (long) doc.getFirstValue(VERSION_FIELD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.solr.handler.component;

import java.io.IOException;
import java.util.Collections;
import java.util.Set;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.response.ResultContext;
Expand Down Expand Up @@ -90,7 +89,7 @@ protected void processIds(

StringBuilder sb = new StringBuilder();

Set<String> fields = Collections.singleton(schema.getUniqueKeyField().getName());
Set<String> fields = Set.of(schema.getUniqueKeyField().getName());
SolrDocumentFetcher docFetcher = searcher.getDocFetcher();
for (DocIterator iter = dl.iterator(); iter.hasNext(); ) {

Expand All @@ -106,7 +105,7 @@ protected void processScores(
throws IOException {

StringBuilder sb = new StringBuilder();
Set<String> fields = Collections.singleton(schema.getUniqueKeyField().getName());
Set<String> fields = Set.of(schema.getUniqueKeyField().getName());
SolrDocumentFetcher docFetcher = searcher.getDocFetcher();
for (DocIterator iter = dl.iterator(); iter.hasNext(); ) {
sb.append(schema.printableUniqueKey(docFetcher.doc(iter.nextDoc(), fields)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.Writer;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
Expand Down Expand Up @@ -87,9 +86,7 @@ public TextResponseWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse
this.rawReturnFields = NO_RAW_FIELDS;
} else {
this.rawFields =
rawFields.size() == 1
? Collections.singleton(rawFields.iterator().next())
: new HashSet<>(rawFields);
rawFields.size() == 1 ? Set.of(rawFields.iterator().next()) : new HashSet<>(rawFields);
this.rawShim = new RawShimTextResponseWriter(this);
this.rawReturnFields = returnFields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.solr.response.transform;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.apache.solr.common.SolrDocument;
Expand Down Expand Up @@ -123,7 +122,7 @@ public String getName() {

@Override
public Collection<String> getRawFields() {
return Collections.singleton(display);
return Set.of(display);
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions solr/core/src/java/org/apache/solr/schema/SchemaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.solr.schema;

import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.apache.solr.client.api.model.SchemaChange.OPERATION_TYPE_PROP;
Expand All @@ -37,6 +36,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.solr.client.api.model.AddCopyFieldOperation;
import org.apache.solr.client.api.model.DeleteCopyFieldOperation;
Expand Down Expand Up @@ -355,7 +355,7 @@ public boolean perform(SchemaChange op, SchemaManager mgr) throws SchemaOperatio
final var deleteFieldTypeOp = (DeleteFieldTypeOperation) op;
String name = ensureNotNull("name", deleteFieldTypeOp.name);
try {
mgr.managedIndexSchema = mgr.managedIndexSchema.deleteFieldTypes(singleton(name));
mgr.managedIndexSchema = mgr.managedIndexSchema.deleteFieldTypes(Set.of(name));
return true;
} catch (Exception e) {
log.error("Could not delete field type", e);
Expand Down Expand Up @@ -385,7 +385,7 @@ public boolean perform(SchemaChange op, SchemaManager mgr) throws SchemaOperatio
final var deleteFieldOp = (DeleteFieldOperation) op;
String name = ensureNotNull("name", deleteFieldOp.name);
try {
mgr.managedIndexSchema = mgr.managedIndexSchema.deleteFields(singleton(name));
mgr.managedIndexSchema = mgr.managedIndexSchema.deleteFields(Set.of(name));
return true;
} catch (Exception e) {
log.error("Could not delete field", e);
Expand All @@ -399,7 +399,7 @@ public boolean perform(SchemaChange op, SchemaManager mgr) throws SchemaOperatio
final var deleteDynFieldOp = (DeleteDynamicFieldOperation) op;
String name = ensureNotNull("name", deleteDynFieldOp.name);
try {
mgr.managedIndexSchema = mgr.managedIndexSchema.deleteDynamicFields(singleton(name));
mgr.managedIndexSchema = mgr.managedIndexSchema.deleteDynamicFields(Set.of(name));
return true;
} catch (Exception e) {
log.error("Could not delete dynamic field", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.lucene.document.Document;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.ScoreDoc;
Expand Down Expand Up @@ -331,6 +331,6 @@ protected NamedList<Object> serializeTopDocs(QueryCommandResult result) throws I

private Document retrieveDocument(
final SchemaField uniqueField, int doc, SolrDocumentFetcher docFetcher) throws IOException {
return docFetcher.doc(doc, Collections.singleton(uniqueField.getName()));
return docFetcher.doc(doc, Set.of(uniqueField.getName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.io.IOException;
import java.io.StringReader;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.apache.lucene.queries.mlt.MoreLikeThis;
import org.apache.lucene.search.Query;
import org.apache.solr.common.SolrException;
Expand Down Expand Up @@ -57,7 +57,7 @@ protected Query likeContent(MoreLikeThis moreLikeThis, String content) throws IO
if (fieldNames.length == 1) {
return moreLikeThis.like(fieldNames[0], new StringReader(content));
} else {
Collection<Object> streamValue = Collections.singleton(content);
Collection<Object> streamValue = Set.of(content);
Map<String, Collection<Object>> multifieldDoc = CollectionUtil.newHashMap(fieldNames.length);
for (String field : fieldNames) {
multifieldDoc.put(field, streamValue);
Expand Down
Loading
Loading