diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java index ff09c23207f..eab7853eefd 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java @@ -25,8 +25,6 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.MasterNodeRequest; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; @@ -41,8 +39,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; */ public class ClusterAllocationExplainRequest extends MasterNodeRequest { - private static ObjectParser PARSER = new ObjectParser( - "cluster/allocation/explain"); + private static ObjectParser PARSER = new ObjectParser<>("cluster/allocation/explain"); static { PARSER.declareString(ClusterAllocationExplainRequest::setIndex, new ParseField("index")); PARSER.declareInt(ClusterAllocationExplainRequest::setShard, new ParseField("shard")); @@ -225,7 +222,7 @@ public class ClusterAllocationExplainRequest extends MasterNodeRequest ParseFieldMatcher.STRICT); + ClusterAllocationExplainRequest req = PARSER.parse(parser, new ClusterAllocationExplainRequest(), null); Exception e = req.validate(); if (e != null) { throw new ElasticsearchParseException("'index', 'shard', and 'primary' must be specified in allocation explain request", e); diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/TransportGetTaskAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/TransportGetTaskAction.java index a6c8941358d..e542984ad35 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/TransportGetTaskAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/get/TransportGetTaskAction.java @@ -31,7 +31,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.AbstractRunnable; @@ -39,10 +38,10 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.tasks.TaskResult; import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.TaskId; import org.elasticsearch.tasks.TaskInfo; +import org.elasticsearch.tasks.TaskResult; import org.elasticsearch.tasks.TaskResultsService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportException; @@ -251,7 +250,7 @@ public class TransportGetTaskAction extends HandledTransportAction ParseFieldMatcher.STRICT); + TaskResult result = TaskResult.PARSER.apply(parser, null); listener.onResponse(new GetTaskResponse(result)); } } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java index 524a21ec632..e97facd748f 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesRequest.java @@ -29,7 +29,6 @@ import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; @@ -42,6 +41,7 @@ import org.elasticsearch.common.xcontent.ObjectParser.ValueType; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryBuilder; @@ -118,8 +118,8 @@ public class IndicesAliasesRequest extends AcknowledgedRequest parser(String name, Supplier supplier) { - ObjectParser parser = new ObjectParser<>(name, supplier); + private static ObjectParser parser(String name, Supplier supplier) { + ObjectParser parser = new ObjectParser<>(name, supplier); parser.declareString((action, index) -> { if (action.indices() != null) { throw new IllegalArgumentException("Only one of [index] and [indices] is supported"); @@ -147,7 +147,7 @@ public class IndicesAliasesRequest extends AcknowledgedRequest ADD_PARSER = parser("add", AliasActions::add); + private static final ObjectParser ADD_PARSER = parser("add", AliasActions::add); static { ADD_PARSER.declareObject(AliasActions::filter, (parser, m) -> { try { @@ -157,18 +157,17 @@ public class IndicesAliasesRequest extends AcknowledgedRequest p.text(), new ParseField("routing"), ValueType.INT); - ADD_PARSER.declareField(AliasActions::indexRouting, p -> p.text(), new ParseField("index_routing"), ValueType.INT); - ADD_PARSER.declareField(AliasActions::searchRouting, p -> p.text(), new ParseField("search_routing"), ValueType.INT); + ADD_PARSER.declareField(AliasActions::routing, XContentParser::text, new ParseField("routing"), ValueType.INT); + ADD_PARSER.declareField(AliasActions::indexRouting, XContentParser::text, new ParseField("index_routing"), ValueType.INT); + ADD_PARSER.declareField(AliasActions::searchRouting, XContentParser::text, new ParseField("search_routing"), ValueType.INT); } - private static final ObjectParser REMOVE_PARSER = parser("remove", AliasActions::remove); - private static final ObjectParser REMOVE_INDEX_PARSER = parser("remove_index", - AliasActions::removeIndex); + private static final ObjectParser REMOVE_PARSER = parser("remove", AliasActions::remove); + private static final ObjectParser REMOVE_INDEX_PARSER = parser("remove_index", AliasActions::removeIndex); /** * Parser for any one {@link AliasAction}. */ - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "alias_action", a -> { // Take the first action and complain if there are more than one actions AliasActions action = null; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java index 8d9b48f2000..69b52e4d2dd 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/Condition.java @@ -20,7 +20,6 @@ package org.elasticsearch.action.admin.indices.rollover; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ObjectParser; @@ -32,8 +31,7 @@ import java.util.Set; */ public abstract class Condition implements NamedWriteable { - public static ObjectParser, ParseFieldMatcherSupplier> PARSER = - new ObjectParser<>("conditions", null); + public static ObjectParser, Void> PARSER = new ObjectParser<>("conditions", null); static { PARSER.declareString((conditions, s) -> conditions.add(new MaxAgeCondition(TimeValue.parseTimeValue(s, MaxAgeCondition.NAME))), diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index ddd58705bea..4804bc577fc 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -25,7 +25,6 @@ import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.TimeValue; @@ -44,23 +43,19 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; */ public class RolloverRequest extends AcknowledgedRequest implements IndicesRequest { - public static final ObjectParser PARSER = - new ObjectParser<>("conditions", null); + public static final ObjectParser PARSER = new ObjectParser<>("conditions", null); static { - PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> - Condition.PARSER.parse(parser, request.conditions, parseFieldMatcherSupplier), + PARSER.declareField((parser, request, context) -> Condition.PARSER.parse(parser, request.conditions, null), new ParseField("conditions"), ObjectParser.ValueType.OBJECT); - PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> - request.createIndexRequest.settings(parser.map()), + PARSER.declareField((parser, request, context) -> request.createIndexRequest.settings(parser.map()), new ParseField("settings"), ObjectParser.ValueType.OBJECT); - PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> { + PARSER.declareField((parser, request, context) -> { for (Map.Entry mappingsEntry : parser.map().entrySet()) { request.createIndexRequest.mapping(mappingsEntry.getKey(), (Map) mappingsEntry.getValue()); } }, new ParseField("mappings"), ObjectParser.ValueType.OBJECT); - PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> - request.createIndexRequest.aliases(parser.map()), + PARSER.declareField((parser, request, context) -> request.createIndexRequest.aliases(parser.map()), new ParseField("aliases"), ObjectParser.ValueType.OBJECT); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/shrink/ShrinkRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/shrink/ShrinkRequest.java index 40a11402501..faa0a63c54d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/shrink/ShrinkRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/shrink/ShrinkRequest.java @@ -25,7 +25,6 @@ import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; @@ -40,14 +39,11 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; */ public class ShrinkRequest extends AcknowledgedRequest implements IndicesRequest { - public static final ObjectParser PARSER = - new ObjectParser<>("shrink_request", null); + public static final ObjectParser PARSER = new ObjectParser<>("shrink_request", null); static { - PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> - request.getShrinkIndexRequest().settings(parser.map()), + PARSER.declareField((parser, request, context) -> request.getShrinkIndexRequest().settings(parser.map()), new ParseField("settings"), ObjectParser.ValueType.OBJECT); - PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> - request.getShrinkIndexRequest().aliases(parser.map()), + PARSER.declareField((parser, request, context) -> request.getShrinkIndexRequest().aliases(parser.map()), new ParseField("aliases"), ObjectParser.ValueType.OBJECT); } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/AllocationId.java b/core/src/main/java/org/elasticsearch/cluster/routing/AllocationId.java index cb0fb487693..9ab91f9f8de 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/AllocationId.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/AllocationId.java @@ -21,8 +21,6 @@ package org.elasticsearch.cluster.routing; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -48,7 +46,7 @@ public class AllocationId implements ToXContent, Writeable { private static final String ID_KEY = "id"; private static final String RELOCATION_ID_KEY = "relocation_id"; - private static final ObjectParser ALLOCATION_ID_PARSER = new ObjectParser<>( + private static final ObjectParser ALLOCATION_ID_PARSER = new ObjectParser<>( "allocationId"); static { @@ -203,6 +201,6 @@ public class AllocationId implements ToXContent, Writeable { } public static AllocationId fromXContent(XContentParser parser) throws IOException { - return ALLOCATION_ID_PARSER.parse(parser, new AllocationId.Builder(), () -> ParseFieldMatcher.STRICT).build(); + return ALLOCATION_ID_PARSER.parse(parser, new AllocationId.Builder(), null).build(); } } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java index 90a591b1199..4ffd70aee1c 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java @@ -30,7 +30,6 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; @@ -50,8 +49,8 @@ public abstract class AbstractAllocateAllocationCommand implements AllocationCom private static final String SHARD_FIELD = "shard"; private static final String NODE_FIELD = "node"; - protected static > ObjectParser createAllocateParser(String command) { - ObjectParser parser = new ObjectParser<>(command); + protected static > ObjectParser createAllocateParser(String command) { + ObjectParser parser = new ObjectParser<>(command); parser.declareString(Builder::setIndex, new ParseField(INDEX_FIELD)); parser.declareInt(Builder::setShard, new ParseField(SHARD_FIELD)); parser.declareString(Builder::setNode, new ParseField(NODE_FIELD)); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java index 82d6f436d2a..157acc0e537 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java @@ -30,8 +30,6 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; @@ -49,8 +47,7 @@ public class AllocateEmptyPrimaryAllocationCommand extends BasePrimaryAllocation public static final String NAME = "allocate_empty_primary"; public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME); - private static final ObjectParser EMPTY_PRIMARY_PARSER = BasePrimaryAllocationCommand - .createAllocatePrimaryParser(NAME); + private static final ObjectParser EMPTY_PRIMARY_PARSER = BasePrimaryAllocationCommand.createAllocatePrimaryParser(NAME); /** * Creates a new {@link AllocateEmptyPrimaryAllocationCommand} @@ -83,7 +80,7 @@ public class AllocateEmptyPrimaryAllocationCommand extends BasePrimaryAllocation @Override public Builder parse(XContentParser parser) throws IOException { - return EMPTY_PRIMARY_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT); + return EMPTY_PRIMARY_PARSER.parse(parser, this, null); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java index 8c47deee66f..6ec09a9bbbb 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java @@ -28,8 +28,6 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; @@ -46,8 +44,7 @@ public class AllocateReplicaAllocationCommand extends AbstractAllocateAllocation public static final String NAME = "allocate_replica"; public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME); - private static final ObjectParser REPLICA_PARSER = - createAllocateParser(NAME); + private static final ObjectParser REPLICA_PARSER = createAllocateParser(NAME); /** * Creates a new {@link AllocateReplicaAllocationCommand} @@ -80,7 +77,7 @@ public class AllocateReplicaAllocationCommand extends AbstractAllocateAllocation @Override public Builder parse(XContentParser parser) throws IOException { - return REPLICA_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT); + return REPLICA_PARSER.parse(parser, this, null); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java index acdd5cae30b..c643fb5c948 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java @@ -28,8 +28,6 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; @@ -46,8 +44,7 @@ public class AllocateStalePrimaryAllocationCommand extends BasePrimaryAllocation public static final String NAME = "allocate_stale_primary"; public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME); - private static final ObjectParser STALE_PRIMARY_PARSER = BasePrimaryAllocationCommand - .createAllocatePrimaryParser(NAME); + private static final ObjectParser STALE_PRIMARY_PARSER = BasePrimaryAllocationCommand.createAllocatePrimaryParser(NAME); /** * Creates a new {@link AllocateStalePrimaryAllocationCommand} @@ -81,7 +78,7 @@ public class AllocateStalePrimaryAllocationCommand extends BasePrimaryAllocation @Override public Builder parse(XContentParser parser) throws IOException { - return STALE_PRIMARY_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT); + return STALE_PRIMARY_PARSER.parse(parser, this, null); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java index f4dc4fba4b8..bccfd97e534 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java @@ -35,8 +35,8 @@ public abstract class BasePrimaryAllocationCommand extends AbstractAllocateAlloc private static final String ACCEPT_DATA_LOSS_FIELD = "accept_data_loss"; - protected static > ObjectParser createAllocatePrimaryParser(String command) { - ObjectParser parser = AbstractAllocateAllocationCommand.createAllocateParser(command); + protected static > ObjectParser createAllocatePrimaryParser(String command) { + ObjectParser parser = AbstractAllocateAllocationCommand.createAllocateParser(command); parser.declareBoolean(Builder::setAcceptDataLoss, new ParseField(ACCEPT_DATA_LOSS_FIELD)); return parser; } diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java index e84890db7c8..0a7e71c6f06 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java @@ -20,7 +20,6 @@ package org.elasticsearch.common.xcontent; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import java.io.IOException; @@ -121,7 +120,7 @@ public final class ObjectParser extends AbstractObjectParser PARSER = new ObjectParser<>("node_meta_data", - Builder::new); + private static ObjectParser PARSER = new ObjectParser<>("node_meta_data", Builder::new); static { PARSER.declareString(Builder::setNodeId, new ParseField(NODE_ID_KEY)); @@ -110,7 +107,7 @@ public final class NodeMetaData { @Override public NodeMetaData fromXContent(XContentParser parser) throws IOException { - return PARSER.apply(parser, () -> ParseFieldMatcher.STRICT).build(); + return PARSER.apply(parser, null).build(); } }; } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java index 84eeda9e1e7..c4cf2afbdaa 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java @@ -23,8 +23,6 @@ import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ObjectParser; @@ -39,7 +37,7 @@ import java.io.IOException; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestIndicesAliasesAction extends BaseRestHandler { - static final ObjectParser PARSER = new ObjectParser<>("aliases"); + static final ObjectParser PARSER = new ObjectParser<>("aliases"); static { PARSER.declareObjectArray((request, actions) -> { for (AliasActions action: actions) { @@ -60,7 +58,7 @@ public class RestIndicesAliasesAction extends BaseRestHandler { indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout())); indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout())); try (XContentParser parser = request.contentParser()) { - PARSER.parse(parser, indicesAliasesRequest, () -> ParseFieldMatcher.STRICT); + PARSER.parse(parser, indicesAliasesRequest, null); } if (indicesAliasesRequest.getAliasActions().isEmpty()) { throw new IllegalArgumentException("No action specified"); diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java index ec42b426401..4eadb6bd847 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -22,7 +22,6 @@ package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.action.admin.indices.rollover.RolloverRequest; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.BaseRestHandler; @@ -44,7 +43,7 @@ public class RestRolloverIndexAction extends BaseRestHandler { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index"), request.param("new_index")); - request.applyContentParser(parser -> RolloverRequest.PARSER.parse(parser, rolloverIndexRequest, () -> ParseFieldMatcher.EMPTY)); + request.applyContentParser(parser -> RolloverRequest.PARSER.parse(parser, rolloverIndexRequest, null)); rolloverIndexRequest.dryRun(request.paramAsBoolean("dry_run", false)); rolloverIndexRequest.timeout(request.paramAsTime("timeout", rolloverIndexRequest.timeout())); rolloverIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", rolloverIndexRequest.masterNodeTimeout())); diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestShrinkIndexAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestShrinkIndexAction.java index b533c8e5e7a..01f99e8403d 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestShrinkIndexAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestShrinkIndexAction.java @@ -23,7 +23,6 @@ import org.elasticsearch.action.admin.indices.shrink.ShrinkRequest; import org.elasticsearch.action.admin.indices.shrink.ShrinkResponse; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -52,7 +51,7 @@ public class RestShrinkIndexAction extends BaseRestHandler { throw new IllegalArgumentException("no source index"); } ShrinkRequest shrinkIndexRequest = new ShrinkRequest(request.param("target"), request.param("index")); - request.applyContentParser(parser -> ShrinkRequest.PARSER.parse(parser, shrinkIndexRequest, () -> ParseFieldMatcher.EMPTY)); + request.applyContentParser(parser -> ShrinkRequest.PARSER.parse(parser, shrinkIndexRequest, null)); shrinkIndexRequest.timeout(request.paramAsTime("timeout", shrinkIndexRequest.timeout())); shrinkIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", shrinkIndexRequest.masterNodeTimeout())); shrinkIndexRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards"))); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/ExtendedBounds.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/ExtendedBounds.java index 85160347612..0c83cde40c4 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/ExtendedBounds.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/ExtendedBounds.java @@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.bucket.histogram; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -45,7 +44,7 @@ public class ExtendedBounds implements ToXContent, Writeable { static final ParseField MIN_FIELD = new ParseField("min"); static final ParseField MAX_FIELD = new ParseField("max"); - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "extended_bounds", a -> { assert a.length == 2; Long min = null; diff --git a/core/src/main/java/org/elasticsearch/tasks/TaskInfo.java b/core/src/main/java/org/elasticsearch/tasks/TaskInfo.java index 9792b894b58..53b7eb76e39 100644 --- a/core/src/main/java/org/elasticsearch/tasks/TaskInfo.java +++ b/core/src/main/java/org/elasticsearch/tasks/TaskInfo.java @@ -20,7 +20,6 @@ package org.elasticsearch.tasks; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; @@ -189,7 +188,7 @@ public final class TaskInfo implements Writeable, ToXContent { return builder; } - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "task_info", a -> { int i = 0; TaskId id = new TaskId((String) a[i++], (Long) a[i++]); diff --git a/core/src/main/java/org/elasticsearch/tasks/TaskResult.java b/core/src/main/java/org/elasticsearch/tasks/TaskResult.java index b5918ad9593..362eb7a4b07 100644 --- a/core/src/main/java/org/elasticsearch/tasks/TaskResult.java +++ b/core/src/main/java/org/elasticsearch/tasks/TaskResult.java @@ -171,7 +171,7 @@ public final class TaskResult implements Writeable, ToXContent { return builder; } - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "stored_task_result", a -> { int i = 0; boolean completed = (boolean) a[i++]; diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/alias/AliasActionsTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/alias/AliasActionsTests.java index b374ce7135c..8cd3f271b7b 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/alias/AliasActionsTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/alias/AliasActionsTests.java @@ -20,7 +20,6 @@ package org.elasticsearch.action.admin.indices.alias; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; @@ -142,7 +141,7 @@ public class AliasActionsTests extends ESTestCase { b.endObject(); b = shuffleXContent(b, "filter"); try (XContentParser parser = createParser(b)) { - AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT); + AliasActions action = AliasActions.PARSER.apply(parser, null); assertEquals(AliasActions.Type.ADD, action.actionType()); assertThat(action.indices(), equalTo(indices)); assertThat(action.aliases(), equalTo(aliases)); @@ -179,7 +178,7 @@ public class AliasActionsTests extends ESTestCase { b.endObject(); b = shuffleXContent(b); try (XContentParser parser = createParser(b)) { - AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT); + AliasActions action = AliasActions.PARSER.apply(parser, null); assertEquals(AliasActions.Type.ADD, action.actionType()); assertThat(action.indices(), arrayContaining(index)); assertThat(action.aliases(), arrayContaining(alias)); @@ -210,7 +209,7 @@ public class AliasActionsTests extends ESTestCase { b.endObject(); b = shuffleXContent(b); try (XContentParser parser = createParser(b)) { - AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT); + AliasActions action = AliasActions.PARSER.apply(parser, null); assertEquals(AliasActions.Type.REMOVE, action.actionType()); assertThat(action.indices(), equalTo(indices)); assertThat(action.aliases(), equalTo(aliases)); @@ -233,7 +232,7 @@ public class AliasActionsTests extends ESTestCase { b.endObject(); b = shuffleXContent(b); try (XContentParser parser = createParser(b)) { - AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT); + AliasActions action = AliasActions.PARSER.apply(parser, null); assertEquals(AliasActions.Type.REMOVE_INDEX, action.actionType()); assertArrayEquals(indices, action.indices()); assertThat(action.aliases(), arrayWithSize(0)); @@ -252,7 +251,7 @@ public class AliasActionsTests extends ESTestCase { } b.endObject(); try (XContentParser parser = createParser(b)) { - Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT)); + Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, null)); assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class)); assertEquals("Only one of [index] and [indices] is supported", e.getCause().getCause().getMessage()); } @@ -270,7 +269,7 @@ public class AliasActionsTests extends ESTestCase { } b.endObject(); try (XContentParser parser = createParser(b)) { - Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT)); + Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, null)); assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class)); assertEquals("Only one of [alias] and [aliases] is supported", e.getCause().getCause().getMessage()); } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java index 17321daf9af..213616eec68 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.admin.indices.rollover; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -40,7 +39,7 @@ public class RolloverRequestTests extends ESTestCase { .field("max_docs", 100) .endObject() .endObject(); - RolloverRequest.PARSER.parse(createParser(builder), request, () -> ParseFieldMatcher.EMPTY); + RolloverRequest.PARSER.parse(createParser(builder), request, null); Set conditions = request.getConditions(); assertThat(conditions.size(), equalTo(2)); for (Condition condition : conditions) { @@ -81,7 +80,7 @@ public class RolloverRequestTests extends ESTestCase { .startObject("alias1").endObject() .endObject() .endObject(); - RolloverRequest.PARSER.parse(createParser(builder), request, () -> ParseFieldMatcher.EMPTY); + RolloverRequest.PARSER.parse(createParser(builder), request, null); Set conditions = request.getConditions(); assertThat(conditions.size(), equalTo(2)); assertThat(request.getCreateIndexRequest().mappings().size(), equalTo(1)); diff --git a/core/src/test/java/org/elasticsearch/common/xcontent/ConstructingObjectParserTests.java b/core/src/test/java/org/elasticsearch/common/xcontent/ConstructingObjectParserTests.java index 6cae59391c5..367559bd9de 100644 --- a/core/src/test/java/org/elasticsearch/common/xcontent/ConstructingObjectParserTests.java +++ b/core/src/test/java/org/elasticsearch/common/xcontent/ConstructingObjectParserTests.java @@ -21,8 +21,6 @@ package org.elasticsearch.common.xcontent; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.AbstractObjectParser.NoContextParser; @@ -43,15 +41,13 @@ import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.nullValue; public class ConstructingObjectParserTests extends ESTestCase { - private static final ParseFieldMatcherSupplier MATCHER = () -> ParseFieldMatcher.STRICT; - public void testNullDeclares() { - ConstructingObjectParser objectParser = new ConstructingObjectParser<>("foo", a -> null); + ConstructingObjectParser objectParser = new ConstructingObjectParser<>("foo", a -> null); Exception e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField(null, (r, c) -> null, new ParseField("test"), ObjectParser.ValueType.STRING)); assertEquals("[consumer] is required", e.getMessage()); e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField( - (o, v) -> {}, (ContextParser) null, + (o, v) -> {}, (ContextParser) null, new ParseField("test"), ObjectParser.ValueType.STRING)); assertEquals("[parser] is required", e.getMessage()); e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField( @@ -82,7 +78,7 @@ public class ConstructingObjectParserTests extends ESTestCase { builder = shuffleXContent(builder); BytesReference bytes = builder.bytes(); try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) { - HasCtorArguments parsed = randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, MATCHER); + HasCtorArguments parsed = randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, null); assertEquals(expected.animal, parsed.animal); assertEquals(expected.vegetable, parsed.vegetable); assertEquals(expected.mineral, parsed.mineral); @@ -102,9 +98,9 @@ public class ConstructingObjectParserTests extends ESTestCase { "{\n" + " \"mineral\": 1\n" + "}"); - ConstructingObjectParser objectParser = randomBoolean() ? HasCtorArguments.PARSER + ConstructingObjectParser objectParser = randomBoolean() ? HasCtorArguments.PARSER : HasCtorArguments.PARSER_VEGETABLE_OPTIONAL; - IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> objectParser.apply(parser, MATCHER)); + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> objectParser.apply(parser, null)); if (objectParser == HasCtorArguments.PARSER) { assertEquals("Required [animal, vegetable]", e.getMessage()); } else { @@ -117,7 +113,7 @@ public class ConstructingObjectParserTests extends ESTestCase { "{\n" + " \"mineral\": 1\n" + "}"); - HasCtorArguments parsed = HasCtorArguments.PARSER_ALL_OPTIONAL.apply(parser, MATCHER); + HasCtorArguments parsed = HasCtorArguments.PARSER_ALL_OPTIONAL.apply(parser, null); assertEquals(1, parsed.mineral); } @@ -128,7 +124,7 @@ public class ConstructingObjectParserTests extends ESTestCase { + " \"animal\": \"cat\"\n" + "}"); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> HasCtorArguments.PARSER.apply(parser, MATCHER)); + () -> HasCtorArguments.PARSER.apply(parser, null)); assertEquals("Required [vegetable]", e.getMessage()); } @@ -140,7 +136,7 @@ public class ConstructingObjectParserTests extends ESTestCase { + "}"); @SuppressWarnings("unchecked") HasCtorArguments parsed = randomFrom(HasCtorArguments.PARSER_VEGETABLE_OPTIONAL, HasCtorArguments.PARSER_ALL_OPTIONAL).apply(parser, - MATCHER); + null); assertEquals(1, parsed.mineral); assertEquals("cat", parsed.animal); } @@ -153,7 +149,7 @@ public class ConstructingObjectParserTests extends ESTestCase { + "}"); @SuppressWarnings("unchecked") IllegalArgumentException e = expectThrows(IllegalArgumentException.class, - () -> randomFrom(HasCtorArguments.PARSER, HasCtorArguments.PARSER_VEGETABLE_OPTIONAL).apply(parser, MATCHER)); + () -> randomFrom(HasCtorArguments.PARSER, HasCtorArguments.PARSER_VEGETABLE_OPTIONAL).apply(parser, null)); assertEquals("Required [animal]", e.getMessage()); } @@ -163,7 +159,7 @@ public class ConstructingObjectParserTests extends ESTestCase { + " \"mineral\": 1,\n" + " \"vegetable\": 2\n" + "}"); - HasCtorArguments parsed = HasCtorArguments.PARSER_ALL_OPTIONAL.apply(parser, MATCHER); + HasCtorArguments parsed = HasCtorArguments.PARSER_ALL_OPTIONAL.apply(parser, null); assertEquals(1, parsed.mineral); assertEquals((Integer) 2, parsed.vegetable); } @@ -176,7 +172,7 @@ public class ConstructingObjectParserTests extends ESTestCase { + " \"vegetable\": 1,\n" + " \"vegetable\": 2\n" + "}"); - Throwable e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, MATCHER)); + Throwable e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, null)); assertEquals("[has_required_arguments] failed to parse field [vegetable]", e.getMessage()); e = e.getCause(); assertThat(e, instanceOf(IllegalArgumentException.class)); @@ -190,7 +186,7 @@ public class ConstructingObjectParserTests extends ESTestCase { + " \"vegetable\": 2,\n" + " \"a\": \"supercalifragilisticexpialidocious\"\n" + "}"); - ParsingException e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, MATCHER)); + ParsingException e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, null)); assertEquals("[has_required_arguments] failed to parse field [a]", e.getMessage()); assertEquals(4, e.getLineNumber()); assertEquals("[a] must be less than 10 characters in length but was [supercalifragilisticexpialidocious]", @@ -204,7 +200,7 @@ public class ConstructingObjectParserTests extends ESTestCase { + " \"animal\": \"cat\"\n," + " \"vegetable\": 2\n" + "}"); - ParsingException e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, MATCHER)); + ParsingException e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, null)); assertEquals("[has_required_arguments] failed to parse field [vegetable]", e.getMessage()); assertEquals(4, e.getLineNumber()); e = (ParsingException) e.getCause(); @@ -220,7 +216,7 @@ public class ConstructingObjectParserTests extends ESTestCase { public void testConstructorArgsMustBeConfigured() throws IOException { class NoConstructorArgs { } - ConstructingObjectParser parser = new ConstructingObjectParser<>( + ConstructingObjectParser parser = new ConstructingObjectParser<>( "constructor_args_required", (a) -> new NoConstructorArgs()); try { parser.apply(createParser(JsonXContent.jsonXContent, "{}"), null); @@ -252,7 +248,7 @@ public class ConstructingObjectParserTests extends ESTestCase { fooSet = true; } } - ConstructingObjectParser parser = new ConstructingObjectParser<>("one_time_test", + ConstructingObjectParser parser = new ConstructingObjectParser<>("one_time_test", (a) -> new CalledOneTime((String) a[0])); parser.declareString(CalledOneTime::setFoo, new ParseField("foo")); parser.declareString(ctorArgOptional ? optionalConstructorArg() : constructorArg(), new ParseField("yeah")); @@ -263,7 +259,7 @@ public class ConstructingObjectParserTests extends ESTestCase { + " \"yeah\": \"!\",\n" + " \"foo\": \"foo\"\n" + "}"); - CalledOneTime result = parser.apply(xcontent, MATCHER); + CalledOneTime result = parser.apply(xcontent, null); assertTrue(result.fooSet); // and ctor arg second just in case @@ -272,7 +268,7 @@ public class ConstructingObjectParserTests extends ESTestCase { + " \"foo\": \"foo\",\n" + " \"yeah\": \"!\"\n" + "}"); - result = parser.apply(xcontent, MATCHER); + result = parser.apply(xcontent, null); assertTrue(result.fooSet); if (ctorArgOptional) { @@ -281,7 +277,7 @@ public class ConstructingObjectParserTests extends ESTestCase { "{\n" + " \"foo\": \"foo\"\n" + "}"); - result = parser.apply(xcontent, MATCHER); + result = parser.apply(xcontent, null); } assertTrue(result.fooSet); } @@ -298,10 +294,10 @@ public class ConstructingObjectParserTests extends ESTestCase { this.test = test; } } - ConstructingObjectParser objectParser = new ConstructingObjectParser<>("foo", true, a -> + ConstructingObjectParser objectParser = new ConstructingObjectParser<>("foo", true, a -> new TestStruct((String) a[0])); objectParser.declareString(constructorArg(), new ParseField("test")); - TestStruct s = objectParser.apply(parser, MATCHER); + TestStruct s = objectParser.apply(parser, null); assertEquals(s.test, "foo"); } @@ -380,17 +376,15 @@ public class ConstructingObjectParserTests extends ESTestCase { * It is normal just to declare a single PARSER but we use a couple of different parsers for testing so we have all of these. Don't * this this style is normal just because it is in the test. */ - public static final ConstructingObjectParser PARSER = buildParser(true, true); - public static final ConstructingObjectParser PARSER_VEGETABLE_OPTIONAL = buildParser( - true, false); - public static final ConstructingObjectParser PARSER_ALL_OPTIONAL = buildParser(false, - false); - public static final List> ALL_PARSERS = unmodifiableList( + public static final ConstructingObjectParser PARSER = buildParser(true, true); + public static final ConstructingObjectParser PARSER_VEGETABLE_OPTIONAL = buildParser(true, false); + public static final ConstructingObjectParser PARSER_ALL_OPTIONAL = buildParser(false, false); + public static final List> ALL_PARSERS = unmodifiableList( Arrays.asList(PARSER, PARSER_VEGETABLE_OPTIONAL, PARSER_ALL_OPTIONAL)); - private static ConstructingObjectParser buildParser(boolean animalRequired, + private static ConstructingObjectParser buildParser(boolean animalRequired, boolean vegetableRequired) { - ConstructingObjectParser parser = new ConstructingObjectParser<>( + ConstructingObjectParser parser = new ConstructingObjectParser<>( "has_required_arguments", a -> new HasCtorArguments((String) a[0], (Integer) a[1])); parser.declareString(animalRequired ? constructorArg() : optionalConstructorArg(), new ParseField("animal")); parser.declareInt(vegetableRequired ? constructorArg() : optionalConstructorArg(), new ParseField("vegetable")); diff --git a/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java b/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java index 3c1bc509328..62e8d32b981 100644 --- a/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java +++ b/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java @@ -19,8 +19,6 @@ package org.elasticsearch.common.xcontent; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.xcontent.AbstractObjectParser.NoContextParser; import org.elasticsearch.common.xcontent.ObjectParser.NamedObjectParser; @@ -39,8 +37,6 @@ import static org.hamcrest.Matchers.hasSize; public class ObjectParserTests extends ESTestCase { - private static final ParseFieldMatcherSupplier STRICT_PARSING = () -> ParseFieldMatcher.STRICT; - public void testBasics() throws IOException { XContentParser parser = createParser(JsonXContent.jsonXContent, "{\n" @@ -60,13 +56,13 @@ public class ObjectParserTests extends ESTestCase { this.ints = ints; } } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING); objectParser.declareInt(TestStruct::setTestNumber, new ParseField("test_number")); objectParser.declareIntArray(TestStruct::setInts, new ParseField("test_array")); - objectParser.parse(parser, s, STRICT_PARSING); + objectParser.parse(parser, s, null); assertEquals(s.test, "foo"); assertEquals(s.testNumber, 2); assertEquals(s.ints, Arrays.asList(1, 2, 3, 4)); @@ -77,12 +73,12 @@ public class ObjectParserTests extends ESTestCase { } public void testNullDeclares() { - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); Exception e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField(null, (r, c) -> null, new ParseField("test"), ObjectParser.ValueType.STRING)); assertEquals("[consumer] is required", e.getMessage()); e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField( - (o, v) -> {}, (ContextParser) null, + (o, v) -> {}, (ContextParser) null, new ParseField("test"), ObjectParser.ValueType.STRING)); assertEquals("[parser] is required", e.getMessage()); e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField( @@ -99,17 +95,17 @@ public class ObjectParserTests extends ESTestCase { public void testObjectOrDefault() throws IOException { XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object\" : { \"test\": 2}}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test")); objectParser.declareObjectOrDefault(StaticTestStruct::setObject, objectParser, StaticTestStruct::new, new ParseField("object")); - StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); + StaticTestStruct s = objectParser.parse(parser, null); assertEquals(s.object.test, 2); parser = createParser(JsonXContent.jsonXContent, "{\"object\" : false }"); - s = objectParser.parse(parser, STRICT_PARSING); + s = objectParser.parse(parser, null); assertNull(s.object); parser = createParser(JsonXContent.jsonXContent, "{\"object\" : true }"); - s = objectParser.parse(parser, STRICT_PARSING); + s = objectParser.parse(parser, null); assertNotNull(s.object); assertEquals(s.object.test, 0); @@ -159,19 +155,14 @@ public class ObjectParserTests extends ESTestCase { } } - class CustomParseFieldMatchSupplier implements ParseFieldMatcherSupplier { + class CustomParseContext { public final ClassicParser parser; - CustomParseFieldMatchSupplier(ClassicParser parser) { + CustomParseContext(ClassicParser parser) { this.parser = parser; } - @Override - public ParseFieldMatcher getParseFieldMatcher() { - return ParseFieldMatcher.EMPTY; - } - public URI parseURI(XContentParser parser) { try { return this.parser.parseURI(parser); @@ -182,10 +173,10 @@ public class ObjectParserTests extends ESTestCase { } XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"url\" : { \"host\": \"http://foobar\", \"port\" : 80}, \"name\" : \"foobarbaz\"}"); - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); objectParser.declareString(Foo::setName, new ParseField("name")); objectParser.declareObjectOrDefault(Foo::setURI, (p, s) -> s.parseURI(p), () -> null, new ParseField("url")); - Foo s = objectParser.parse(parser, new Foo(), new CustomParseFieldMatchSupplier(new ClassicParser())); + Foo s = objectParser.parse(parser, new Foo(), new CustomParseContext(new ClassicParser())); assertEquals(s.uri.getHost(), "foobar"); assertEquals(s.uri.getPort(), 80); assertEquals(s.name, "foobarbaz"); @@ -197,12 +188,12 @@ public class ObjectParserTests extends ESTestCase { public void setTest(int test) { } } - ObjectParser objectParser = new ObjectParser<>("the_parser"); + ObjectParser objectParser = new ObjectParser<>("the_parser"); TestStruct s = new TestStruct(); objectParser.declareInt(TestStruct::setTest, new ParseField("test")); try { - objectParser.parse(parser, s, STRICT_PARSING); + objectParser.parse(parser, s, null); fail("numeric value expected"); } catch (ParsingException ex) { assertEquals(ex.getMessage(), "[the_parser] failed to parse field [test]"); @@ -211,7 +202,7 @@ public class ObjectParserTests extends ESTestCase { parser = createParser(JsonXContent.jsonXContent, "{\"not_supported_field\" : \"foo\"}"); try { - objectParser.parse(parser, s, STRICT_PARSING); + objectParser.parse(parser, s, null); fail("field not supported"); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "[the_parser] unknown field [not_supported_field], parser not found"); @@ -222,11 +213,11 @@ public class ObjectParserTests extends ESTestCase { class TestStruct { public String test; } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); XContentParser parser = createParser(XContentType.JSON.xContent(), "{\"old_test\" : \"foo\"}"); objectParser.declareField((i, v, c) -> v.test = i.text(), new ParseField("test", "old_test"), ObjectParser.ValueType.STRING); - objectParser.parse(parser, s, () -> ParseFieldMatcher.EMPTY); + objectParser.parse(parser, s, null); assertEquals("foo", s.test); assertWarnings("Deprecated field [old_test] used, expected [test] instead"); } @@ -236,12 +227,12 @@ public class ObjectParserTests extends ESTestCase { class TestStruct { public String test; } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("numeric_value"), ObjectParser.ValueType.FLOAT); try { - objectParser.parse(parser, s, STRICT_PARSING); + objectParser.parse(parser, s, null); fail("wrong type - must be number"); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "[foo] numeric_value doesn't support values of type: VALUE_BOOLEAN"); @@ -254,40 +245,40 @@ public class ObjectParserTests extends ESTestCase { public int test; TestStruct object; } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); s.object = new TestStruct(); objectParser.declareField((i, c, x) -> c.test = i.intValue(), new ParseField("test"), ValueType.INT); - objectParser.declareField((i, c, x) -> objectParser.parse(parser, c.object, STRICT_PARSING), new ParseField("object"), + objectParser.declareField((i, c, x) -> objectParser.parse(parser, c.object, null), new ParseField("object"), ValueType.OBJECT); - objectParser.parse(parser, s, STRICT_PARSING); + objectParser.parse(parser, s, null); assertEquals(s.test, 1); assertEquals(s.object.test, 2); } public void testParseNestedShortcut() throws IOException { XContentParser parser = createParser(JsonXContent.jsonXContent, "{ \"test\" : 1, \"object\" : { \"test\": 2}}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test")); objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object")); - StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); + StaticTestStruct s = objectParser.parse(parser, null); assertEquals(s.test, 1); assertEquals(s.object.test, 2); } public void testEmptyObject() throws IOException { XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object\" : {}}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object")); - StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); + StaticTestStruct s = objectParser.parse(parser, null); assertNotNull(s.object); } public void testEmptyObjectInArray() throws IOException { XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object_array\" : [{}]}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareObjectArray(StaticTestStruct::setObjectArray, objectParser, new ParseField("object_array")); - StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); + StaticTestStruct s = objectParser.parse(parser, null); assertNotNull(s.objectArray); } @@ -322,9 +313,9 @@ public class ObjectParserTests extends ESTestCase { } } XContentParser parser = createParser(JsonXContent.jsonXContent, "{ \"test\" : \"FOO\" }"); - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); objectParser.declareString((struct, value) -> struct.set(TestEnum.valueOf(value)), new ParseField("test")); - TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING); + TestStruct s = objectParser.parse(parser, new TestStruct(), null); assertEquals(s.test, TestEnum.FOO); } @@ -418,7 +409,7 @@ public class ObjectParserTests extends ESTestCase { this.string_or_null = string_or_null; } } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); objectParser.declareInt(TestStruct::setInt_field, new ParseField("int_field")); objectParser.declareIntArray(TestStruct::setInt_array_field, new ParseField("int_array_field")); objectParser.declareLong(TestStruct::setLong_field, new ParseField("long_field")); @@ -432,7 +423,7 @@ public class ObjectParserTests extends ESTestCase { objectParser.declareStringOrNull(TestStruct::setString_or_null, new ParseField("string_or_null")); objectParser.declareBoolean(TestStruct::setNull_value, new ParseField("boolean_field")); - TestStruct parse = objectParser.parse(parser, new TestStruct(), STRICT_PARSING); + TestStruct parse = objectParser.parse(parser, new TestStruct(), null); assertArrayEquals(parse.double_array_field.toArray(), Arrays.asList(2.1d).toArray()); assertEquals(parse.double_field, 2.1d, 0.0d); @@ -461,7 +452,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": {\n" + " \"a\": {}" + "}}"); - NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING); + NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, null); assertThat(h.named, hasSize(1)); assertEquals("a", h.named.get(0).name); assertFalse(h.namedSuppliedInOrder); @@ -472,7 +463,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " {\"a\": {}}" + "]}"); - NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING); + NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, null); assertThat(h.named, hasSize(1)); assertEquals("a", h.named.get(0).name); assertTrue(h.namedSuppliedInOrder); @@ -483,7 +474,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " {\"a\": {}, \"b\": {}}" + "]}"); - ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING)); + ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals( "[named] can be a single object with any number of fields or an array where each entry is an object with a single field", @@ -495,7 +486,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " {}" + "]}"); - ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING)); + ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals( "[named] can be a single object with any number of fields or an array where each entry is an object with a single field", @@ -507,7 +498,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " \"junk\"" + "]}"); - ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING)); + ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals( "[named] can be a single object with any number of fields or an array where each entry is an object with a single field", @@ -521,12 +512,12 @@ public class ObjectParserTests extends ESTestCase { + "]}"); // Create our own parser for this test so we can disable support for the "ordered" mode specified by the array above - ObjectParser objectParser = new ObjectParser<>("named_object_holder", + ObjectParser objectParser = new ObjectParser<>("named_object_holder", NamedObjectHolder::new); objectParser.declareNamedObjects(NamedObjectHolder::setNamed, NamedObject.PARSER, new ParseField("named")); // Now firing the xml through it fails - ParsingException e = expectThrows(ParsingException.class, () -> objectParser.apply(parser, STRICT_PARSING)); + ParsingException e = expectThrows(ParsingException.class, () -> objectParser.apply(parser, null)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals("[named] doesn't support arrays. Use a single object with multiple fields.", e.getCause().getMessage()); } @@ -545,9 +536,9 @@ public class ObjectParserTests extends ESTestCase { class TestStruct { public String test; } - ObjectParser objectParser = new ObjectParser<>("foo", true, null); + ObjectParser objectParser = new ObjectParser<>("foo", true, null); objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING); - TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING); + TestStruct s = objectParser.parse(parser, new TestStruct(), null); assertEquals(s.test, "foo"); } @@ -569,9 +560,9 @@ public class ObjectParserTests extends ESTestCase { class TestStruct { public String test; } - ObjectParser objectParser = new ObjectParser<>("foo", true, null); + ObjectParser objectParser = new ObjectParser<>("foo", true, null); objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING); - TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING); + TestStruct s = objectParser.parse(parser, new TestStruct(), null); assertEquals(s.test, "foo"); } @@ -596,14 +587,14 @@ public class ObjectParserTests extends ESTestCase { class TestStruct { public String test; } - ObjectParser objectParser = new ObjectParser<>("foo", true, null); + ObjectParser objectParser = new ObjectParser<>("foo", true, null); objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING); - TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING); + TestStruct s = objectParser.parse(parser, new TestStruct(), null); assertEquals(s.test, "foo"); } static class NamedObjectHolder { - public static final ObjectParser PARSER = new ObjectParser<>("named_object_holder", + public static final ObjectParser PARSER = new ObjectParser<>("named_object_holder", NamedObjectHolder::new); static { PARSER.declareNamedObjects(NamedObjectHolder::setNamed, NamedObject.PARSER, NamedObjectHolder::keepNamedInOrder, @@ -623,11 +614,11 @@ public class ObjectParserTests extends ESTestCase { } public static class NamedObject { - public static final NamedObjectParser PARSER; + public static final NamedObjectParser PARSER; static { - ObjectParser parser = new ObjectParser<>("named"); + ObjectParser parser = new ObjectParser<>("named"); parser.declareInt(NamedObject::setFoo, new ParseField("foo")); - PARSER = (XContentParser p, ParseFieldMatcherSupplier v, String name) -> parser.parse(p, new NamedObject(name), STRICT_PARSING); + PARSER = (XContentParser p, Void v, String name) -> parser.parse(p, new NamedObject(name), null); } final String name; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/ExtendedBoundsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/ExtendedBoundsTests.java index 9853d09e31e..16ba3ed6958 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/ExtendedBoundsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/ExtendedBoundsTests.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.bucket.histogram; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; @@ -174,7 +173,7 @@ public class ExtendedBoundsTests extends ESTestCase { assertThat(token, equalTo(XContentParser.Token.FIELD_NAME)); assertThat(in.currentName(), equalTo(ExtendedBounds.EXTENDED_BOUNDS_FIELD.getPreferredName())); - ExtendedBounds read = ExtendedBounds.PARSER.apply(in, () -> ParseFieldMatcher.STRICT); + ExtendedBounds read = ExtendedBounds.PARSER.apply(in, null); assertEquals(orig, read); } catch (Exception e) { throw new Exception("Error parsing [" + out.bytes().utf8ToString() + "]", e); diff --git a/core/src/test/java/org/elasticsearch/tasks/TaskResultTests.java b/core/src/test/java/org/elasticsearch/tasks/TaskResultTests.java index 396a7da2673..ff8fcd8fbaf 100644 --- a/core/src/test/java/org/elasticsearch/tasks/TaskResultTests.java +++ b/core/src/test/java/org/elasticsearch/tasks/TaskResultTests.java @@ -20,7 +20,6 @@ package org.elasticsearch.tasks; import org.elasticsearch.client.Requests; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -67,7 +66,7 @@ public class TaskResultTests extends ESTestCase { result.toXContent(builder, ToXContent.EMPTY_PARAMS); try (XContentBuilder shuffled = shuffleXContent(builder); XContentParser parser = createParser(shuffled)) { - read = TaskResult.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT); + read = TaskResult.PARSER.apply(parser, null); } } catch (IOException e) { throw new IOException("Error processing [" + result + "]", e); diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java index 3c0f5d2772d..165188430e4 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java @@ -22,7 +22,6 @@ package org.elasticsearch.index.reindex; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestController; @@ -66,7 +65,7 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler> consumers = new HashMap<>(); consumers.put("conflicts", o -> internal.setConflicts((String) o)); - consumers.put("script", o -> internal.setScript(parseScript((Map)o, parseFieldMatcher))); + consumers.put("script", o -> internal.setScript(parseScript((Map)o))); parseInternalRequest(internal, request, consumers); @@ -75,7 +74,7 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler config, ParseFieldMatcher parseFieldMatcher) { + private static Script parseScript(Map config) { String script = null; ScriptType type = null; String lang = DEFAULT_SCRIPT_LANG; diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteResponseParsers.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteResponseParsers.java index 42e8a598edd..8b9dc7b8de7 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteResponseParsers.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteResponseParsers.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.reindex.remote; import org.elasticsearch.Version; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.xcontent.ConstructingObjectParser; @@ -55,7 +54,7 @@ final class RemoteResponseParsers { /** * Parser for an individual {@code hit} element. */ - public static final ConstructingObjectParser HIT_PARSER = + public static final ConstructingObjectParser HIT_PARSER = new ConstructingObjectParser<>("hit", true, a -> { int i = 0; String index = (String) a[i++]; @@ -93,7 +92,7 @@ final class RemoteResponseParsers { String routing; String parent; } - ObjectParser fieldsParser = new ObjectParser<>("fields", Fields::new); + ObjectParser fieldsParser = new ObjectParser<>("fields", Fields::new); HIT_PARSER.declareObject((hit, fields) -> { hit.setRouting(fields.routing); hit.setParent(fields.parent); @@ -106,7 +105,7 @@ final class RemoteResponseParsers { /** * Parser for the {@code hits} element. Parsed to an array of {@code [total (Long), hits (List)]}. */ - public static final ConstructingObjectParser HITS_PARSER = + public static final ConstructingObjectParser HITS_PARSER = new ConstructingObjectParser<>("hits", true, a -> a); static { HITS_PARSER.declareLong(constructorArg(), new ParseField("total")); @@ -116,7 +115,7 @@ final class RemoteResponseParsers { /** * Parser for {@code failed} shards in the {@code _shards} elements. */ - public static final ConstructingObjectParser SEARCH_FAILURE_PARSER = + public static final ConstructingObjectParser SEARCH_FAILURE_PARSER = new ConstructingObjectParser<>("failure", true, a -> { int i = 0; String index = (String) a[i++]; @@ -149,7 +148,7 @@ final class RemoteResponseParsers { * Parser for the {@code _shards} element. Throws everything out except the errors array if there is one. If there isn't one then it * parses to an empty list. */ - public static final ConstructingObjectParser, ParseFieldMatcherSupplier> SHARDS_PARSER = + public static final ConstructingObjectParser, Void> SHARDS_PARSER = new ConstructingObjectParser<>("_shards", true, a -> { @SuppressWarnings("unchecked") List failures = (List) a[0]; @@ -160,7 +159,7 @@ final class RemoteResponseParsers { SHARDS_PARSER.declareObjectArray(optionalConstructorArg(), SEARCH_FAILURE_PARSER, new ParseField("failures")); } - public static final ConstructingObjectParser RESPONSE_PARSER = + public static final ConstructingObjectParser RESPONSE_PARSER = new ConstructingObjectParser<>("search_response", true, a -> { int i = 0; Throwable catastrophicFailure = (Throwable) a[i++]; @@ -199,9 +198,9 @@ final class RemoteResponseParsers { * Collects stuff about Throwables and attempts to rebuild them. */ public static class ThrowableBuilder { - public static final BiFunction PARSER; + public static final BiFunction PARSER; static { - ObjectParser parser = new ObjectParser<>("reason", true, ThrowableBuilder::new); + ObjectParser parser = new ObjectParser<>("reason", true, ThrowableBuilder::new); PARSER = parser.andThen(ThrowableBuilder::build); parser.declareString(ThrowableBuilder::setType, new ParseField("type")); parser.declareString(ThrowableBuilder::setReason, new ParseField("reason")); @@ -265,10 +264,10 @@ final class RemoteResponseParsers { /** * Parses the main action to return just the {@linkplain Version} that it returns. We throw everything else out. */ - public static final ConstructingObjectParser MAIN_ACTION_PARSER = new ConstructingObjectParser<>( + public static final ConstructingObjectParser MAIN_ACTION_PARSER = new ConstructingObjectParser<>( "/", true, a -> (Version) a[0]); static { - ConstructingObjectParser versionParser = new ConstructingObjectParser<>( + ConstructingObjectParser versionParser = new ConstructingObjectParser<>( "version", true, a -> Version.fromString((String) a[0])); versionParser.declareString(constructorArg(), new ParseField("number")); MAIN_ACTION_PARSER.declareObject(constructorArg(), versionParser, new ParseField("version")); diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteScrollableHitSource.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteScrollableHitSource.java index 2971319726b..d4dfe69a727 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteScrollableHitSource.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteScrollableHitSource.java @@ -34,8 +34,6 @@ import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.ResponseListener; import org.elasticsearch.client.RestClient; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -142,7 +140,7 @@ public class RemoteScrollableHitSource extends ScrollableHitSource { } private void execute(String method, String uri, Map params, HttpEntity entity, - BiFunction parser, Consumer listener) { + BiFunction parser, Consumer listener) { // Preserve the thread context so headers survive after the call ThreadContext.StoredContext ctx = threadPool.getThreadContext().newStoredContext(); class RetryHelper extends AbstractRunnable { @@ -176,7 +174,7 @@ public class RemoteScrollableHitSource extends ScrollableHitSource { // EMPTY is safe here because we don't call namedObject try (XContentParser xContentParser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, content)) { - parsedResponse = parser.apply(xContentParser, () -> ParseFieldMatcher.STRICT); + parsedResponse = parser.apply(xContentParser, null); } catch (ParsingException e) { /* Because we're streaming the response we can't get a copy of it here. The best we can do is hint that it * is totally wrong and we're probably not talking to Elasticsearch. */