Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
Expand Down Expand Up @@ -65,8 +64,8 @@ public class MissingDoclet extends StandardDoclet {
DocletEnvironment docEnv;
DocTrees docTrees;
Elements elementUtils;
Set<String> ignored = Collections.emptySet();
Set<String> methodPackages = Collections.emptySet();
Set<String> ignored = Set.of();
Set<String> methodPackages = Set.of();

@Override
public Set<Doclet.Option> getSupportedOptions() {
Expand Down Expand Up @@ -373,7 +372,7 @@ private Stream<Element> superTypeForInheritDoc(Element type) {
clazz.getInterfaces().stream()
.filter(tm -> tm.getKind() == TypeKind.DECLARED)
.map(tm -> ((DeclaredType) tm).asElement())
.collect(Collectors.toList());
.toList();

Stream<Element> result = interfaces.stream();
result = Stream.concat(result, interfaces.stream().flatMap(this::superTypeForInheritDoc));
Expand Down
11 changes: 10 additions & 1 deletion gradle/validation/forbidden-apis/defaults.all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ java.io.File#delete() @ use Files.delete for real exception, IOUtils.deleteFiles

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

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

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

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

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 Expand Up @@ -102,4 +111,4 @@ java.nio.file.Paths#get(**)
java.nio.file.Path#startsWith(java.lang.String)

@defaultMessage Use NIO Path instead of File
java.io.File
java.io.File
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
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/api/ApiBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public ApiBag(boolean isCoreSpecific) {
public synchronized List<Api> registerObject(Object o) {
List<Api> l = AnnotatedApi.getApis(o);
for (Api api : l) {
register(api, Collections.emptyMap());
register(api, Map.of());
}
return l;
}

public synchronized void register(Api api) {
register(api, Collections.emptyMap());
register(api, Map.of());
}

public synchronized void register(Api api, Map<String, String> nameSubstitutes) {
Expand Down
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/api/ApiSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.solr.api;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

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

/** Whether this should be made available at the regular legacy path */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -424,7 +423,7 @@ public void init() throws Exception {
throw new RuntimeException("Must have a no-arg constructor or CoreContainer constructor ");
}
Map<String, Object> config =
(Map<String, Object>) holder.original.getOrDefault("config", Collections.emptyMap());
(Map<String, Object>) holder.original.getOrDefault("config", Map.of());
configure(instance, config, holder.meta);
if (instance instanceof ResourceLoaderAware) {
try {
Expand Down
3 changes: 1 addition & 2 deletions solr/core/src/java/org/apache/solr/api/V2HttpCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -488,7 +487,7 @@ private String computeEndpointPath() {
// myColName -> collection
final Map<String, String> pathTemplateValKey;
if (pathTemplateKeyVal.isEmpty()) { // typical
pathTemplateValKey = Collections.emptyMap();
pathTemplateValKey = Map.of();
} else if (pathTemplateKeyVal.size() == 1) { // typical
Map.Entry<String, String> entry = pathTemplateKeyVal.entrySet().iterator().next();
pathTemplateValKey = Map.of(entry.getValue(), entry.getKey());
Expand Down
3 changes: 1 addition & 2 deletions solr/core/src/java/org/apache/solr/cloud/CloudUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -136,7 +135,7 @@ public static Map<String, byte[]> getTrustedKeys(SolrZkClient zk, String dir) {
}
} catch (KeeperException.NoNodeException e) {
log.info("Error fetching key names");
return Collections.emptyMap();
return Map.of();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to read crypto keys", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
Expand Down Expand Up @@ -387,7 +388,7 @@ private void applyUpdate() throws KeeperException, InterruptedException {
// For now trying to diverge as little as possible from existing data structures and code
// given the need to support both the old way (Overseer) and new way (distributed) of handling
// cluster state update.
final Set<String> liveNodes = Collections.emptySet();
final Set<String> liveNodes = Set.of();

// Per Replica States updates are done before all other updates and not subject to the number
// of attempts of CAS made here, given they have their own CAS strategy and implementation
Expand All @@ -412,7 +413,7 @@ private void applyUpdate() throws KeeperException, InterruptedException {
// state. Knowing about all collections in the cluster might not be needed.
ClusterState initialClusterState;
if (updater.isCollectionCreation()) {
initialClusterState = new ClusterState(liveNodes, Collections.emptyMap());
initialClusterState = new ClusterState(liveNodes, Map.of());
} else {
// Get the state for existing data in ZK (and if no data exists we should fail)
initialClusterState = fetchStateForCollection();
Expand Down Expand Up @@ -586,7 +587,7 @@ private ClusterState fetchStateForCollection() throws KeeperException, Interrupt
ZkClientClusterStateProvider.createFromJsonSupportingLegacyConfigName(
stat.getVersion(),
data,
Collections.emptySet(),
Set.of(),
updater.getCollectionName(),
zkStateReader.getZkClient(),
Instant.ofEpochMilli(stat.getCtime()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public Map<String, Object> getConfigMetadata(String configName) throws IOExcepti
Utils.fromJSON(zkClient.getData(CONFIGS_ZKNODE + "/" + configName, null, null));
return data;
} catch (KeeperException.NoNodeException e) {
return Collections.emptyMap();
return Map.of();
} catch (KeeperException | InterruptedException e) {
throw new IOException("Error getting config metadata", SolrZkClient.checkInterrupted(e));
}
Expand All @@ -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.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -345,7 +344,7 @@ public Stats getZkStats() {
@Override
public Map<String, Object> getStats() {
if (stats == null) {
return Collections.emptyMap();
return Map.of();
}
Map<String, Object> res = new HashMap<>();
res.put("queueLength", stats.getQueueLength());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ List<ReplicaPosition> assign(
default Map<Replica, String> computeReplicaBalancing(
SolrCloudManager solrCloudManager, Set<String> nodes, int maxBalanceSkew)
throws AssignmentException, IOException, InterruptedException {
return Collections.emptyMap();
return Map.of();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.apache.solr.cloud.api.collections.CollectionHandlingUtils.ShardRequestTracker;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
Expand Down Expand Up @@ -168,7 +168,7 @@ public void call(AdminCmdContext adminCmdContext, ZkNodeProps message, NamedList
backupMgr.downloadConfigDir(configName, cc.getConfigSetService());
}

// Save the collection's state. Can be part of the monolithic clusterstate.json or a
// Save the collection's state. Can be part of the monolithic clusterstate.json or an
// individual state.json. Since we don't want to distinguish we extract the state and back it
// up as a separate json
DocCollection collectionState =
Expand Down Expand Up @@ -285,7 +285,7 @@ private Replica selectReplicaWithSnapshot(CollectionSnapshotMetaData snapshotMet
x.getState() != State.DOWN && snapshotMeta.isSnapshotExists(slice.getName(), x))
.findFirst();

if (!r.isPresent()) {
if (r.isEmpty()) {
throw new SolrException(
ErrorCode.SERVER_ERROR,
"Unable to find any live replica with a snapshot named "
Expand Down Expand Up @@ -462,7 +462,7 @@ private void copyIndexFiles(
SolrZkClient zkClient = ccc.getZkStateReader().getZkClient();
snapshotMeta =
SolrSnapshotManager.getCollectionLevelSnapshot(zkClient, collectionName, commitName);
if (!snapshotMeta.isPresent()) {
if (snapshotMeta.isEmpty()) {
throw new SolrException(
ErrorCode.BAD_REQUEST,
"Snapshot with name "
Expand All @@ -488,7 +488,7 @@ private void copyIndexFiles(
backupName,
backupPath);

Collection<String> shardsToConsider = Collections.emptySet();
Collection<String> shardsToConsider = Set.of();
if (snapshotMeta.isPresent()) {
shardsToConsider = snapshotMeta.get().getShards();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.solr.cloud.api.collections;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand All @@ -43,7 +42,7 @@ public void call(AdminCmdContext adminCmdContext, ZkNodeProps message, NamedList
Set<String> nodes;
Object nodesRaw = message.get(CollectionParams.NODES);
if (nodesRaw == null) {
nodes = Collections.emptySet();
nodes = Set.of();
} else if (nodesRaw instanceof Set) {
nodes = (Set<String>) nodesRaw;
} else if (nodesRaw instanceof Collection) {
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 @@ -70,10 +70,10 @@
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import java.lang.invoke.MethodHandles;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.solr.cloud.DistributedClusterStateUpdater;
Expand Down Expand Up @@ -275,13 +275,7 @@ public void call(
params.set(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.RELOAD.toString());

CollectionHandlingUtils.collectionCmd(
adminCmdContext,
message,
params,
results,
Replica.State.ACTIVE,
Collections.emptySet(),
ccc);
adminCmdContext, message, params, results, Replica.State.ACTIVE, Set.of(), ccc);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static void commit(
parentShardLeader.getName(),
updateResponse,
slice,
Collections.emptySet(),
Set.of(),
null);
} catch (Exception e) {
CollectionHandlingUtils.processResponse(
Expand All @@ -247,7 +247,7 @@ static void commit(
parentShardLeader.getCoreName(),
updateResponse,
slice,
Collections.emptySet(),
Set.of(),
null);
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
Expand Down Expand Up @@ -742,7 +742,7 @@ void processResponses(
ShardHandler shardHandler,
boolean abortOnError,
String msgOnError) {
processResponses(results, shardHandler, abortOnError, msgOnError, Collections.emptySet());
processResponses(results, shardHandler, abortOnError, msgOnError, Set.of());
}

void processResponses(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -415,8 +416,7 @@ public void call(AdminCmdContext adminCmdContext, ZkNodeProps message, NamedList
nodeName, replicas.get(e.getKey()).getCoreName(), params, shardHandler);
}

shardRequestTracker.processResponses(
results, shardHandler, false, null, Collections.emptySet());
shardRequestTracker.processResponses(results, shardHandler, false, null, Set.of());
boolean failure =
results.get("failure") != null
&& ((SimpleOrderedMap<?>) results.get("failure")).size() > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void call(AdminCmdContext adminCmdContext, ZkNodeProps message, NamedList
protected Set<String> getNodesFromParam(ZkNodeProps message, String paramName) {
Object rawParam = message.get(paramName);
if (rawParam == null) {
return Collections.emptySet();
return Set.of();
} else if (rawParam instanceof Set) {
return (Set<String>) rawParam;
} else if (rawParam instanceof Collection) {
Expand Down
Loading
Loading