Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-16427: Enable error-prone ClassInitializationDeadlock rule #2881

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion gradle/validation/error-prone.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ allprojects { prj ->
'-Xep:ChainedAssertionLosesContext:WARN',
'-Xep:CharacterGetNumericValue:WARN',
'-Xep:ClassCanBeStatic:WARN',
// '-Xep:ClassInitializationDeadlock:WARN', // todo check if useful or comment why not
'-Xep:ClassInitializationDeadlock:WARN',
'-Xep:ClassNewInstance:WARN',
// '-Xep:CloseableProvides:OFF', // we don't use this annotation
'-Xep:ClosingStandardOutputStreams:WARN',
Expand Down
5 changes: 3 additions & 2 deletions solr/core/src/java/org/apache/solr/cloud/ActionThrottle.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.invoke.MethodHandles;
import java.util.concurrent.TimeUnit;
import org.apache.solr.common.util.TimeSource;
import org.apache.solr.common.util.TimeSources;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -33,7 +34,7 @@ public class ActionThrottle {
private final TimeSource timeSource;

public ActionThrottle(String name, long minMsBetweenActions) {
this(name, minMsBetweenActions, TimeSource.NANO_TIME);
this(name, minMsBetweenActions, TimeSources.NANO_TIME);
}

public ActionThrottle(String name, long minMsBetweenActions, TimeSource timeSource) {
Expand All @@ -43,7 +44,7 @@ public ActionThrottle(String name, long minMsBetweenActions, TimeSource timeSour
}

public ActionThrottle(String name, long minMsBetweenActions, long lastActionStartedAt) {
this(name, minMsBetweenActions, lastActionStartedAt, TimeSource.NANO_TIME);
this(name, minMsBetweenActions, lastActionStartedAt, TimeSources.NANO_TIME);
}

public ActionThrottle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocCollection.CollectionStateProps;
import org.apache.solr.common.cloud.DocRouter;
import org.apache.solr.common.cloud.DocRouters;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.SolrZkClient;
Expand Down Expand Up @@ -113,7 +113,7 @@ private static Map<String, Object> makeCollectionPropsAndDefaults() {
Map<String, Object> propsAndDefaults =
Utils.makeMap(
CollectionStateProps.DOC_ROUTER,
(Object) DocRouter.DEFAULT_NAME,
(Object) DocRouters.DEFAULT_NAME,
CollectionStateProps.REPLICATION_FACTOR,
"1",
CollectionStateProps.PER_REPLICA_STATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocCollection.CollectionStateProps;
import org.apache.solr.common.cloud.DocRouter;
import org.apache.solr.common.cloud.DocRouters;
import org.apache.solr.common.cloud.ImplicitDocRouter;
import org.apache.solr.common.cloud.PerReplicaStates;
import org.apache.solr.common.cloud.PerReplicaStatesOps;
Expand Down Expand Up @@ -144,7 +144,7 @@ public void call(ClusterState clusterState, ZkNodeProps message, NamedList<Objec
CollectionHandlingUtils.validateConfigOrThrowSolrException(
ccc.getCoreContainer().getConfigSetService(), configName);

String router = message.getStr("router.name", DocRouter.DEFAULT_NAME);
String router = message.getStr("router.name", DocRouters.DEFAULT_NAME);

// fail fast if parameters are wrong or incomplete
List<String> shardNames = populateShardNames(message, router);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocRouter;
import org.apache.solr.common.cloud.DocRouters;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.ReplicaCount;
import org.apache.solr.common.cloud.ZkNodeProps;
Expand Down Expand Up @@ -255,7 +256,7 @@ public void call(ClusterState clusterState, ZkNodeProps message, NamedList<Objec
int numShards = message.getInt(ZkStateReader.NUM_SHARDS_PROP, coll.getActiveSlices().size());
DocRouter router = coll.getRouter();
if (router == null) {
router = DocRouter.DEFAULT;
router = DocRouters.DEFAULT;
}

String configName = message.getStr(ZkStateReader.CONFIGNAME_PROP, coll.getConfigName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.apache.solr.common.cloud.CompositeIdRouter;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocRouter;
import org.apache.solr.common.cloud.DocRouters;
import org.apache.solr.common.cloud.PlainIdRouter;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.ReplicaCount;
Expand Down Expand Up @@ -1010,7 +1011,7 @@ public static Slice getParentSlice(
AtomicReference<String> slice,
String splitKey) {
DocCollection collection = clusterState.getCollection(collectionName);
DocRouter router = collection.getRouter() != null ? collection.getRouter() : DocRouter.DEFAULT;
DocRouter router = collection.getRouter() != null ? collection.getRouter() : DocRouters.DEFAULT;

Slice parentSlice;

Expand Down Expand Up @@ -1076,7 +1077,7 @@ public static String fillRanges(
if (range == null) {
range = new PlainIdRouter().fullRange();
}
DocRouter router = collection.getRouter() != null ? collection.getRouter() : DocRouter.DEFAULT;
DocRouter router = collection.getRouter() != null ? collection.getRouter() : DocRouters.DEFAULT;
if (rangesStr != null) {
String[] ranges = rangesStr.split(",");
if (ranges.length == 0 || ranges.length == 1) {
Expand All @@ -1087,7 +1088,7 @@ public static String fillRanges(
for (int i = 0; i < ranges.length; i++) {
String r = ranges[i];
try {
subRanges.add(DocRouter.DEFAULT.fromString(r));
subRanges.add(DocRouters.DEFAULT.fromString(r));
} catch (Exception e) {
throw new SolrException(
SolrException.ErrorCode.BAD_REQUEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocCollection.CollectionStateProps;
import org.apache.solr.common.cloud.DocRouter;
import org.apache.solr.common.cloud.DocRouters;
import org.apache.solr.common.cloud.ImplicitDocRouter;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
Expand Down Expand Up @@ -67,8 +68,8 @@ public ZkWriteCommand createCollection(ClusterState clusterState, ZkNodeProps me

Map<String, Object> routerSpec = DocRouter.getRouterSpec(message);
String routerName =
routerSpec.get(NAME) == null ? DocRouter.DEFAULT_NAME : (String) routerSpec.get(NAME);
DocRouter router = DocRouter.getDocRouter(routerName);
routerSpec.get(NAME) == null ? DocRouters.DEFAULT_NAME : (String) routerSpec.get(NAME);
DocRouter router = DocRouters.getDocRouter(routerName);

Object messageShardsObj = message.get("shards");

Expand All @@ -80,7 +81,7 @@ public ZkWriteCommand createCollection(ClusterState clusterState, ZkNodeProps me
List<String> shardNames = new ArrayList<>();

if (router instanceof ImplicitDocRouter) {
getShardNames(shardNames, message.getStr("shards", DocRouter.DEFAULT_NAME));
getShardNames(shardNames, message.getStr("shards", DocRouters.DEFAULT_NAME));
} else {
int numShards = message.getInt(ZkStateReader.NUM_SHARDS_PROP, -1);
if (numShards < 1)
Expand Down
9 changes: 6 additions & 3 deletions solr/core/src/java/org/apache/solr/core/SolrCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
import org.apache.solr.response.SmileResponseWriter;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.response.XMLResponseWriter;
import org.apache.solr.response.transform.TransformerFactories;
import org.apache.solr.response.transform.TransformerFactory;
import org.apache.solr.rest.ManagedResourceStorage;
import org.apache.solr.rest.ManagedResourceStorage.StorageIO;
Expand All @@ -144,9 +145,11 @@
import org.apache.solr.schema.ManagedIndexSchema;
import org.apache.solr.schema.SimilarityFactory;
import org.apache.solr.search.QParserPlugin;
import org.apache.solr.search.QParserPlugins;
import org.apache.solr.search.SolrFieldCacheBean;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.search.ValueSourceParser;
import org.apache.solr.search.ValueSourceParsers;
import org.apache.solr.search.stats.LocalStatsCache;
import org.apache.solr.search.stats.StatsCache;
import org.apache.solr.update.DefaultSolrCoreState;
Expand Down Expand Up @@ -1128,9 +1131,9 @@ protected SolrCore(
initIndex(prev != null, reload);

initWriters();
qParserPlugins.init(QParserPlugin.standardPlugins, this);
valueSourceParsers.init(ValueSourceParser.standardValueSourceParsers, this);
transformerFactories.init(TransformerFactory.defaultFactories, this);
qParserPlugins.init(QParserPlugins.standardPlugins, this);
valueSourceParsers.init(ValueSourceParsers.standardValueSourceParsers, this);
transformerFactories.init(TransformerFactories.defaultFactories, this);
loadSearchComponents();
updateProcessors.init(Collections.emptyMap(), this);

Expand Down
7 changes: 4 additions & 3 deletions solr/core/src/java/org/apache/solr/handler/admin/SplitOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocCollection.CollectionStateProps;
import org.apache.solr.common.cloud.DocRouter;
import org.apache.solr.common.cloud.DocRouters;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.params.CommonAdminParams;
import org.apache.solr.common.params.CoreAdminParams;
Expand Down Expand Up @@ -104,7 +105,7 @@ public void execute(CoreAdminHandler.CallInfo it) throws Exception {
ranges = new ArrayList<>(rangesArr.length);
for (String r : rangesArr) {
try {
ranges.add(DocRouter.DEFAULT.fromString(r));
ranges.add(DocRouters.DEFAULT.fromString(r));
} catch (Exception e) {
throw new SolrException(
SolrException.ErrorCode.BAD_REQUEST,
Expand Down Expand Up @@ -151,7 +152,7 @@ public void execute(CoreAdminHandler.CallInfo it) throws Exception {
DocCollection collection = clusterState.getCollection(collectionName);
String sliceName = parentCore.getCoreDescriptor().getCloudDescriptor().getShardId();
Slice slice = collection.getSlice(sliceName);
router = collection.getRouter() != null ? collection.getRouter() : DocRouter.DEFAULT;
router = collection.getRouter() != null ? collection.getRouter() : DocRouters.DEFAULT;
if (ranges == null) {
DocRouter.Range currentRange = slice.getRange();
ranges = currentRange != null ? router.partitionRange(partitions, currentRange) : null;
Expand Down Expand Up @@ -269,7 +270,7 @@ private void handleGetRanges(CoreAdminHandler.CallInfo it, String coreName) thro
Slice slice = collection.getSlice(sliceName);
CompositeIdRouter router =
(CompositeIdRouter)
(collection.getRouter() != null ? collection.getRouter() : DocRouter.DEFAULT);
(collection.getRouter() != null ? collection.getRouter() : DocRouters.DEFAULT);
DocRouter.Range currentRange = slice.getRange();

Object routerObj =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.solr.response.transform;

import java.util.HashMap;
import java.util.Map;

public class TransformerFactories {

private TransformerFactories() {}

public static final Map<String, TransformerFactory> defaultFactories = new HashMap<>(9, 1.0f);

static {
defaultFactories.put("explain", new ExplainAugmenterFactory());
defaultFactories.put("value", new ValueAugmenterFactory());
defaultFactories.put("docid", new DocIdAugmenterFactory());
defaultFactories.put("shard", new ShardAugmenterFactory());
defaultFactories.put("child", new ChildDocTransformerFactory());
defaultFactories.put("subquery", new SubQueryAugmenterFactory());
defaultFactories.put("json", new RawValueTransformerFactory("json"));
defaultFactories.put("xml", new RawValueTransformerFactory("xml"));
defaultFactories.put("geo", new GeoTransformerFactory());
defaultFactories.put("core", new CoreAugmenterFactory());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.solr.response.transform;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.solr.common.params.SolrParams;
Expand Down Expand Up @@ -105,18 +104,10 @@ default boolean mayModifyValue() {
}
}

public static final Map<String, TransformerFactory> defaultFactories = new HashMap<>(9, 1.0f);

static {
defaultFactories.put("explain", new ExplainAugmenterFactory());
defaultFactories.put("value", new ValueAugmenterFactory());
defaultFactories.put("docid", new DocIdAugmenterFactory());
defaultFactories.put("shard", new ShardAugmenterFactory());
defaultFactories.put("child", new ChildDocTransformerFactory());
defaultFactories.put("subquery", new SubQueryAugmenterFactory());
defaultFactories.put("json", new RawValueTransformerFactory("json"));
defaultFactories.put("xml", new RawValueTransformerFactory("xml"));
defaultFactories.put("geo", new GeoTransformerFactory());
defaultFactories.put("core", new CoreAugmenterFactory());
}
/**
* @deprecated Use {@link TransformerFactories#defaultFactories} instead.
*/
@Deprecated(since = "9.8", forRemoval = true)
public static final Map<String, TransformerFactory> defaultFactories =
TransformerFactories.defaultFactories;
}
4 changes: 2 additions & 2 deletions solr/core/src/java/org/apache/solr/schema/SchemaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.util.CommandOperation;
import org.apache.solr.common.util.TimeSource;
import org.apache.solr.common.util.TimeSources;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader;
Expand Down Expand Up @@ -100,7 +100,7 @@ public List<Map<String, Object>> performOperations() throws Exception {

private List<Map<String, Object>> doOperations(List<CommandOperation> operations)
throws InterruptedException, IOException, KeeperException {
TimeOut timeOut = new TimeOut(updateTimeOut, TimeUnit.SECONDS, TimeSource.NANO_TIME);
TimeOut timeOut = new TimeOut(updateTimeOut, TimeUnit.SECONDS, TimeSources.NANO_TIME);
SolrCore core = req.getCore();
String errorMsg = "Unable to persist managed schema. ";
List<Map<String, Object>> errors = Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ protected ValueSource parseValueSource(int flags) throws SyntaxError {
if ((ch >= '0' && ch <= '9') || ch == '.' || ch == '+' || ch == '-') {
Number num = sp.getNumber();
if (num instanceof Long) {
valueSource = new ValueSourceParser.LongConstValueSource(num.longValue());
valueSource = new ValueSourceParsers.LongConstValueSource(num.longValue());
} else if (num instanceof Double) {
valueSource = new DoubleConstValueSource(num.doubleValue());
} else {
Expand Down Expand Up @@ -482,9 +482,9 @@ protected ValueSource parseValueSource(int flags) throws SyntaxError {
sp.expect(")");
} else {
if ("true".equals(id)) {
valueSource = ValueSourceParser.BoolConstValueSource.TRUE;
valueSource = ValueSourceParsers.BoolConstValueSource.TRUE;
} else if ("false".equals(id)) {
valueSource = ValueSourceParser.BoolConstValueSource.FALSE;
valueSource = ValueSourceParsers.BoolConstValueSource.FALSE;
} else {
if ((flags & FLAG_USE_FIELDNAME_SOURCE) != 0) {
// Don't try to create a ValueSource for the field, just use a placeholder.
Expand Down
Loading
Loading