Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
8 changes: 7 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,12 @@ 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()

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 +108,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/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 @@ -387,7 +387,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 Down Expand Up @@ -586,7 +586,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 @@ -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 @@ -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
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 @@ -18,7 +18,6 @@

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -96,7 +95,7 @@ public void close() throws IOException {
protected void fireEvent(ClusterEvent event) {
synchronized (listeners) {
listeners
.getOrDefault(event.getType(), Collections.emptySet())
.getOrDefault(event.getType(), Set.of())
.forEach(
listener -> {
if (log.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.solr.cluster.placement.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -46,7 +45,7 @@ public class AttributeFetcherImpl implements AttributeFetcher {
Set<NodeMetric<?>> requestedNodeMetricSnitchTags = new HashSet<>();
Map<SolrCollection, Set<ReplicaMetric<?>>> requestedCollectionMetrics = new HashMap<>();

Set<Node> nodes = Collections.emptySet();
Set<Node> nodes = Set.of();

private final SolrCloudManager cloudManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ AffinityNode newNodeFromMetrics(
Optional<String> nodePropOpt =
attrValues.getSystemProperty(node, AffinityPlacementConfig.NODE_TYPE_SYSPROP);
if (nodePropOpt.isEmpty()) {
nodeType = Collections.emptySet();
nodeType = Set.of();
} else {
nodeType = new HashSet<>(StrUtils.splitSmart(nodePropOpt.get(), ','));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public boolean hasShardOnNode(Shard shard) {
public Set<Replica> getReplicasForShardOnNode(Shard shard) {
return Optional.ofNullable(replicas.get(shard.getCollection().getName()))
.map(m -> m.get(shard.getShardName()))
.orElseGet(Collections::emptySet);
.orElseGet(Set::of);
}

public abstract int calcWeight();
Expand Down 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
13 changes: 6 additions & 7 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,9 +63,9 @@ public class CoreSorter {
}
}

// Prioritize replicas where most no:of other nodes are waiting for
// For example if 1 other replicas are waiting for this replica, then
// prioritize that over the replica were zero other nodes are waiting
// Prioritize replicas where the greatest number of other nodes are waiting.
// For example, if one other replica is waiting for this replica, then
// prioritize that over a replica where zero other nodes are waiting
if (c1.totalReplicasInLiveNodes > c2.totalReplicasInLiveNodes) return -1;
if (c2.totalReplicasInLiveNodes > c1.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();
}
}
Loading
Loading