Move more XContent.createParser calls to non-deprecated version (#28670)

* Move more XContent.createParser calls to non-deprecated version

This moves more of the callers to pass in the DeprecationHandler.

Relates to #28504

* Use parser's deprecation handler where available
This commit is contained in:
Lee Hinman 2018-02-14 09:01:40 -07:00 committed by GitHub
parent 53c38cc8fe
commit 7c1f5f5054
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 84 additions and 49 deletions

View File

@ -29,6 +29,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -108,7 +109,8 @@ public class TransportSearchTemplateAction extends HandledTransportAction<Search
return null; return null;
} }
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(xContentRegistry, source)) { try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, source)) {
SearchSourceBuilder builder = SearchSourceBuilder.searchSource(); SearchSourceBuilder builder = SearchSourceBuilder.searchSource();
builder.parseXContent(parser); builder.parseXContent(parser);
builder.explain(searchTemplateRequest.isExplain()); builder.explain(searchTemplateRequest.isExplain());

View File

@ -57,6 +57,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -731,8 +732,9 @@ public class PercolateQueryBuilder extends AbstractQueryBuilder<PercolateQueryBu
BytesRef qbSource = binaryDocValues.binaryValue(); BytesRef qbSource = binaryDocValues.binaryValue();
if (qbSource.length > 0) { if (qbSource.length > 0) {
XContent xContent = PercolatorFieldMapper.QUERY_BUILDER_CONTENT_TYPE.xContent(); XContent xContent = PercolatorFieldMapper.QUERY_BUILDER_CONTENT_TYPE.xContent();
try (XContentParser sourceParser = xContent.createParser(context.getXContentRegistry(), qbSource.bytes, try (XContentParser sourceParser = xContent
qbSource.offset, qbSource.length)) { .createParser(context.getXContentRegistry(), LoggingDeprecationHandler.INSTANCE,
qbSource.bytes, qbSource.offset, qbSource.length)) {
return parseQuery(context, mapUnmappedFieldsAsString, sourceParser); return parseQuery(context, mapUnmappedFieldsAsString, sourceParser);
} }
} else { } else {

View File

@ -31,6 +31,7 @@ import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.Build; import org.elasticsearch.Build;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -90,6 +91,7 @@ public class WildflyIT extends LuceneTestCase {
XContentParser parser = XContentParser parser =
JsonXContent.jsonXContent.createParser( JsonXContent.jsonXContent.createParser(
new NamedXContentRegistry(ClusterModule.getNamedXWriteables()), new NamedXContentRegistry(ClusterModule.getNamedXWriteables()),
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
response.getEntity().getContent())) { response.getEntity().getContent())) {
final Map<String, Object> map = parser.map(); final Map<String, Object> map = parser.map();
assertThat(map.get("first_name"), equalTo("John")); assertThat(map.get("first_name"), equalTo("John"));

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
@ -120,7 +121,8 @@ public class AliasValidator extends AbstractComponent {
public void validateAliasFilter(String alias, String filter, QueryShardContext queryShardContext, public void validateAliasFilter(String alias, String filter, QueryShardContext queryShardContext,
NamedXContentRegistry xContentRegistry) { NamedXContentRegistry xContentRegistry) {
assert queryShardContext != null; assert queryShardContext != null;
try (XContentParser parser = XContentFactory.xContent(filter).createParser(xContentRegistry, filter)) { try (XContentParser parser = XContentFactory.xContent(filter)
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, filter)) {
validateAliasFilter(parser, queryShardContext); validateAliasFilter(parser, queryShardContext);
} catch (Exception e) { } catch (Exception e) {
throw new IllegalArgumentException("failed to parse filter for alias [" + alias + "]", e); throw new IllegalArgumentException("failed to parse filter for alias [" + alias + "]", e);
@ -135,7 +137,8 @@ public class AliasValidator extends AbstractComponent {
public void validateAliasFilter(String alias, byte[] filter, QueryShardContext queryShardContext, public void validateAliasFilter(String alias, byte[] filter, QueryShardContext queryShardContext,
NamedXContentRegistry xContentRegistry) { NamedXContentRegistry xContentRegistry) {
assert queryShardContext != null; assert queryShardContext != null;
try (XContentParser parser = XContentFactory.xContent(filter).createParser(xContentRegistry, filter)) { try (XContentParser parser = XContentFactory.xContent(filter)
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, filter)) {
validateAliasFilter(parser, queryShardContext); validateAliasFilter(parser, queryShardContext);
} catch (Exception e) { } catch (Exception e) {
throw new IllegalArgumentException("failed to parse filter for alias [" + alias + "]", e); throw new IllegalArgumentException("failed to parse filter for alias [" + alias + "]", e);

View File

@ -38,6 +38,7 @@ import org.elasticsearch.common.unit.RatioValue;
import org.elasticsearch.common.unit.SizeValue; import org.elasticsearch.common.unit.SizeValue;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -1116,7 +1117,8 @@ public final class Settings implements ToXContentFragment {
* Loads settings from the actual string content that represents them using {@link #fromXContent(XContentParser)} * Loads settings from the actual string content that represents them using {@link #fromXContent(XContentParser)}
*/ */
public Builder loadFromSource(String source, XContentType xContentType) { public Builder loadFromSource(String source, XContentType xContentType) {
try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = XContentFactory.xContent(xContentType)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
this.put(fromXContent(parser, true, true)); this.put(fromXContent(parser, true, true));
} catch (Exception e) { } catch (Exception e) {
throw new SettingsException("Failed to load settings from [" + source + "]", e); throw new SettingsException("Failed to load settings from [" + source + "]", e);

View File

@ -77,8 +77,8 @@ public class ParseFieldRegistry<T> {
* @return The value being looked up. Never null. * @return The value being looked up. Never null.
* @throws ParsingException if the named thing isn't in the registry or the name was deprecated and deprecated names aren't supported. * @throws ParsingException if the named thing isn't in the registry or the name was deprecated and deprecated names aren't supported.
*/ */
public T lookup(String name, XContentLocation xContentLocation) { public T lookup(String name, XContentLocation xContentLocation, DeprecationHandler deprecationHandler) {
T value = lookupReturningNullIfNotFound(name); T value = lookupReturningNullIfNotFound(name, deprecationHandler);
if (value == null) { if (value == null) {
throw new ParsingException(xContentLocation, "no [" + registryName + "] registered for [" + name + "]"); throw new ParsingException(xContentLocation, "no [" + registryName + "] registered for [" + name + "]");
} }
@ -92,14 +92,14 @@ public class ParseFieldRegistry<T> {
* @return The value being looked up or null if it wasn't found. * @return The value being looked up or null if it wasn't found.
* @throws ParsingException if the named thing isn't in the registry or the name was deprecated and deprecated names aren't supported. * @throws ParsingException if the named thing isn't in the registry or the name was deprecated and deprecated names aren't supported.
*/ */
public T lookupReturningNullIfNotFound(String name) { public T lookupReturningNullIfNotFound(String name, DeprecationHandler deprecationHandler) {
Tuple<ParseField, T> parseFieldAndValue = registry.get(name); Tuple<ParseField, T> parseFieldAndValue = registry.get(name);
if (parseFieldAndValue == null) { if (parseFieldAndValue == null) {
return null; return null;
} }
ParseField parseField = parseFieldAndValue.v1(); ParseField parseField = parseFieldAndValue.v1();
T value = parseFieldAndValue.v2(); T value = parseFieldAndValue.v2();
boolean match = parseField.match(name, LoggingDeprecationHandler.INSTANCE); boolean match = parseField.match(name, deprecationHandler);
//this is always expected to match, ParseField is useful for deprecation warnings etc. here //this is always expected to match, ParseField is useful for deprecation warnings etc. here
assert match : "ParseField did not match registered name [" + name + "][" + registryName + "]"; assert match : "ParseField did not match registered name [" + name + "][" + registryName + "]";
return value; return value;

View File

@ -149,17 +149,6 @@ public interface XContent {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, data); return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, data);
} }
/**
* Creates a parser over the provided bytes using
* {@link LoggingDeprecationHandler}.
* @deprecated This is a temporary shim so we can migrate all calls to createParser incrementally.
* Use {@link #createParser(NamedXContentRegistry, DeprecationHandler, byte[], int, int)} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, data, offset, length);
}
/** /**
* Creates a parser over the provided bytes using * Creates a parser over the provided bytes using
* {@link LoggingDeprecationHandler}. * {@link LoggingDeprecationHandler}.

View File

@ -71,7 +71,7 @@ public class XContentHelper {
} }
return XContentFactory.xContent(xContentType).createParser(xContentRegistry, deprecationHandler, compressedInput); return XContentFactory.xContent(xContentType).createParser(xContentRegistry, deprecationHandler, compressedInput);
} else { } else {
return xContentType.xContent().createParser(xContentRegistry, bytes.streamInput()); return xContentType.xContent().createParser(xContentRegistry, deprecationHandler, bytes.streamInput());
} }
} }
@ -117,7 +117,8 @@ public class XContentHelper {
*/ */
public static Map<String, Object> convertToMap(XContent xContent, String string, boolean ordered) throws ElasticsearchParseException { public static Map<String, Object> convertToMap(XContent xContent, String string, boolean ordered) throws ElasticsearchParseException {
// It is safe to use EMPTY here because this never uses namedObject // It is safe to use EMPTY here because this never uses namedObject
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, string)) { try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, string)) {
return ordered ? parser.mapOrdered() : parser.map(); return ordered ? parser.mapOrdered() : parser.map();
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchParseException("Failed to parse content to map", e); throw new ElasticsearchParseException("Failed to parse content to map", e);
@ -131,7 +132,8 @@ public class XContentHelper {
public static Map<String, Object> convertToMap(XContent xContent, InputStream input, boolean ordered) public static Map<String, Object> convertToMap(XContent xContent, InputStream input, boolean ordered)
throws ElasticsearchParseException { throws ElasticsearchParseException {
// It is safe to use EMPTY here because this never uses namedObject // It is safe to use EMPTY here because this never uses namedObject
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, input)) { try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, input)) {
return ordered ? parser.mapOrdered() : parser.map(); return ordered ? parser.mapOrdered() : parser.map();
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchParseException("Failed to parse content to map", e); throw new ElasticsearchParseException("Failed to parse content to map", e);
@ -161,7 +163,7 @@ public class XContentHelper {
// It is safe to use EMPTY here because this never uses namedObject // It is safe to use EMPTY here because this never uses namedObject
try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE, bytes.streamInput())) { DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput())) {
parser.nextToken(); parser.nextToken();
XContentBuilder builder = XContentFactory.jsonBuilder(); XContentBuilder builder = XContentFactory.jsonBuilder();
if (prettyPrint) { if (prettyPrint) {

View File

@ -31,6 +31,7 @@ import com.fasterxml.jackson.core.util.JsonGeneratorDelegate;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -314,7 +315,8 @@ public class JsonXContentGenerator implements XContentGenerator {
public void writeRawField(String name, InputStream content, XContentType contentType) throws IOException { public void writeRawField(String name, InputStream content, XContentType contentType) throws IOException {
if (mayWriteRawData(contentType) == false) { if (mayWriteRawData(contentType) == false) {
// EMPTY is safe here because we never call namedObject when writing raw data // EMPTY is safe here because we never call namedObject when writing raw data
try (XContentParser parser = XContentFactory.xContent(contentType).createParser(NamedXContentRegistry.EMPTY, content)) { try (XContentParser parser = XContentFactory.xContent(contentType)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, content)) {
parser.nextToken(); parser.nextToken();
writeFieldName(name); writeFieldName(name);
copyCurrentStructure(parser); copyCurrentStructure(parser);
@ -392,7 +394,8 @@ public class JsonXContentGenerator implements XContentGenerator {
protected void copyRawValue(BytesReference content, XContent xContent) throws IOException { protected void copyRawValue(BytesReference content, XContent xContent) throws IOException {
// EMPTY is safe here because we never call namedObject // EMPTY is safe here because we never call namedObject
try (StreamInput input = content.streamInput(); try (StreamInput input = content.streamInput();
XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, input)) { XContentParser parser = xContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, input)) {
copyCurrentStructure(parser); copyCurrentStructure(parser);
} }
} }

View File

@ -35,6 +35,7 @@ import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.lucene.store.IndexOutputOutputStream; import org.elasticsearch.common.lucene.store.IndexOutputOutputStream;
import org.elasticsearch.common.lucene.store.InputStreamIndexInput; import org.elasticsearch.common.lucene.store.InputStreamIndexInput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -192,8 +193,9 @@ public abstract class MetaDataStateFormat<T> {
long filePointer = indexInput.getFilePointer(); long filePointer = indexInput.getFilePointer();
long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer; long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer;
try (IndexInput slice = indexInput.slice("state_xcontent", filePointer, contentSize)) { try (IndexInput slice = indexInput.slice("state_xcontent", filePointer, contentSize)) {
try (XContentParser parser = XContentFactory.xContent(FORMAT).createParser(namedXContentRegistry, try (XContentParser parser = XContentFactory.xContent(FORMAT)
new InputStreamIndexInput(slice, contentSize))) { .createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE,
new InputStreamIndexInput(slice, contentSize))) {
return fromXContent(parser); return fromXContent(parser);
} }
} }

View File

@ -23,6 +23,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -162,7 +163,8 @@ public class DocumentMapperParser {
private Tuple<String, Map<String, Object>> extractMapping(String type, String source) throws MapperParsingException { private Tuple<String, Map<String, Object>> extractMapping(String type, String source) throws MapperParsingException {
Map<String, Object> root; Map<String, Object> root;
try (XContentParser parser = XContentType.JSON.xContent().createParser(xContentRegistry, source)) { try (XContentParser parser = XContentType.JSON.xContent()
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, source)) {
root = parser.mapOrdered(); root = parser.mapOrdered();
} catch (Exception e) { } catch (Exception e) {
throw new MapperParsingException("failed to parse mapping definition", e); throw new MapperParsingException("failed to parse mapping definition", e);

View File

@ -37,6 +37,7 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -200,7 +201,8 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
* Parses the mappings (formatted as JSON) into a map * Parses the mappings (formatted as JSON) into a map
*/ */
public static Map<String, Object> parseMapping(NamedXContentRegistry xContentRegistry, String mappingSource) throws Exception { public static Map<String, Object> parseMapping(NamedXContentRegistry xContentRegistry, String mappingSource) throws Exception {
try (XContentParser parser = XContentType.JSON.xContent().createParser(xContentRegistry, mappingSource)) { try (XContentParser parser = XContentType.JSON.xContent()
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, mappingSource)) {
return parser.map(); return parser.map();
} }
} }

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -158,7 +159,8 @@ public class WrapperQueryBuilder extends AbstractQueryBuilder<WrapperQueryBuilde
@Override @Override
protected QueryBuilder doRewrite(QueryRewriteContext context) throws IOException { protected QueryBuilder doRewrite(QueryRewriteContext context) throws IOException {
try (XContentParser qSourceParser = XContentFactory.xContent(source).createParser(context.getXContentRegistry(), source)) { try (XContentParser qSourceParser = XContentFactory.xContent(source)
.createParser(context.getXContentRegistry(), LoggingDeprecationHandler.INSTANCE, source)) {
final QueryBuilder queryBuilder = parseInnerQueryBuilder(qSourceParser).rewrite(context); final QueryBuilder queryBuilder = parseInnerQueryBuilder(qSourceParser).rewrite(context);
if (boost() != DEFAULT_BOOST || queryName() != null) { if (boost() != DEFAULT_BOOST || queryName() != null) {

View File

@ -62,6 +62,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.iterable.Iterables; import org.elasticsearch.common.util.iterable.Iterables;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -1236,7 +1237,8 @@ public class IndicesService extends AbstractLifecycleComponent
/* Being static, parseAliasFilter doesn't have access to whatever guts it needs to parse a query. Instead of passing in a bunch /* Being static, parseAliasFilter doesn't have access to whatever guts it needs to parse a query. Instead of passing in a bunch
* of dependencies we pass in a function that can perform the parsing. */ * of dependencies we pass in a function that can perform the parsing. */
CheckedFunction<byte[], QueryBuilder, IOException> filterParser = bytes -> { CheckedFunction<byte[], QueryBuilder, IOException> filterParser = bytes -> {
try (XContentParser parser = XContentFactory.xContent(bytes).createParser(xContentRegistry, bytes)) { try (XContentParser parser = XContentFactory.xContent(bytes)
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, bytes)) {
return parseInnerQueryBuilder(parser); return parseInnerQueryBuilder(parser);
} }
}; };

View File

@ -21,6 +21,7 @@ package org.elasticsearch.search.aggregations.bucket.significant;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ParseFieldRegistry; import org.elasticsearch.common.xcontent.ParseFieldRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -96,7 +97,7 @@ public class SignificantTermsAggregationBuilder extends ValuesSourceAggregationB
aggregationParser.declareObject(SignificantTermsAggregationBuilder::significanceHeuristic, aggregationParser.declareObject(SignificantTermsAggregationBuilder::significanceHeuristic,
(p, context) -> { (p, context) -> {
SignificanceHeuristicParser significanceHeuristicParser = significanceHeuristicParserRegistry SignificanceHeuristicParser significanceHeuristicParser = significanceHeuristicParserRegistry
.lookupReturningNullIfNotFound(name); .lookupReturningNullIfNotFound(name, p.getDeprecationHandler());
return significanceHeuristicParser.parse(p); return significanceHeuristicParser.parse(p);
}, },
new ParseField(name)); new ParseField(name));

View File

@ -22,6 +22,7 @@ package org.elasticsearch.search.aggregations.bucket.significant;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ParseFieldRegistry; import org.elasticsearch.common.xcontent.ParseFieldRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -111,7 +112,7 @@ public class SignificantTextAggregationBuilder extends AbstractAggregationBuilde
PARSER.declareObject(SignificantTextAggregationBuilder::significanceHeuristic, PARSER.declareObject(SignificantTextAggregationBuilder::significanceHeuristic,
(p, context) -> { (p, context) -> {
SignificanceHeuristicParser significanceHeuristicParser = significanceHeuristicParserRegistry SignificanceHeuristicParser significanceHeuristicParser = significanceHeuristicParserRegistry
.lookupReturningNullIfNotFound(name); .lookupReturningNullIfNotFound(name, p.getDeprecationHandler());
return significanceHeuristicParser.parse(p); return significanceHeuristicParser.parse(p);
}, new ParseField(name)); }, new ParseField(name));
} }

View File

@ -23,6 +23,7 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.ParseFieldRegistry; import org.elasticsearch.common.xcontent.ParseFieldRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -402,7 +403,8 @@ public class MovAvgPipelineAggregationBuilder extends AbstractPipelineAggregatio
factory.predict(predict); factory.predict(predict);
} }
if (model != null) { if (model != null) {
MovAvgModel.AbstractModelParser modelParser = movingAverageMdelParserRegistry.lookup(model, parser.getTokenLocation()); MovAvgModel.AbstractModelParser modelParser = movingAverageMdelParserRegistry.lookup(model,
parser.getTokenLocation(), parser.getDeprecationHandler());
MovAvgModel movAvgModel; MovAvgModel movAvgModel;
try { try {
movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window()); movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window());

View File

@ -30,6 +30,7 @@ import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.CharsRefBuilder; import org.apache.lucene.util.CharsRefBuilder;
import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.AbstractQueryBuilder; import org.elasticsearch.index.query.AbstractQueryBuilder;
@ -115,8 +116,8 @@ public final class PhraseSuggester extends Suggester<PhraseSuggestionContext> {
vars.put(SUGGESTION_TEMPLATE_VAR_NAME, spare.toString()); vars.put(SUGGESTION_TEMPLATE_VAR_NAME, spare.toString());
QueryShardContext shardContext = suggestion.getShardContext(); QueryShardContext shardContext = suggestion.getShardContext();
final String querySource = scriptFactory.newInstance(vars).execute(); final String querySource = scriptFactory.newInstance(vars).execute();
try (XContentParser parser = XContentFactory.xContent(querySource).createParser(shardContext.getXContentRegistry(), try (XContentParser parser = XContentFactory.xContent(querySource)
querySource)) { .createParser(shardContext.getXContentRegistry(), LoggingDeprecationHandler.INSTANCE, querySource)) {
QueryBuilder innerQueryBuilder = AbstractQueryBuilder.parseInnerQueryBuilder(parser); QueryBuilder innerQueryBuilder = AbstractQueryBuilder.parseInnerQueryBuilder(parser);
final ParsedQuery parsedQuery = shardContext.toQuery(innerQueryBuilder); final ParsedQuery parsedQuery = shardContext.toQuery(innerQueryBuilder);
collateMatch = Lucene.exists(searcher, parsedQuery.query()); collateMatch = Lucene.exists(searcher, parsedQuery.query());

View File

@ -753,7 +753,8 @@ public abstract class BaseXContentTestCase extends ESTestCase {
generator.writeEndObject(); generator.writeEndObject();
} }
XContentParser parser = xcontentType().xContent().createParser(NamedXContentRegistry.EMPTY, os.toByteArray()); XContentParser parser = xcontentType().xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, os.toByteArray());
assertEquals(Token.START_OBJECT, parser.nextToken()); assertEquals(Token.START_OBJECT, parser.nextToken());
assertEquals(Token.FIELD_NAME, parser.nextToken()); assertEquals(Token.FIELD_NAME, parser.nextToken());
assertEquals("bar", parser.currentName()); assertEquals("bar", parser.currentName());
@ -787,7 +788,8 @@ public abstract class BaseXContentTestCase extends ESTestCase {
generator.writeRawValue(new BytesArray(rawData)); generator.writeRawValue(new BytesArray(rawData));
} }
XContentParser parser = xcontentType().xContent().createParser(NamedXContentRegistry.EMPTY, os.toByteArray()); XContentParser parser = xcontentType().xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, os.toByteArray());
assertEquals(Token.START_OBJECT, parser.nextToken()); assertEquals(Token.START_OBJECT, parser.nextToken());
assertEquals(Token.FIELD_NAME, parser.nextToken()); assertEquals(Token.FIELD_NAME, parser.nextToken());
assertEquals("foo", parser.currentName()); assertEquals("foo", parser.currentName());
@ -803,7 +805,8 @@ public abstract class BaseXContentTestCase extends ESTestCase {
generator.writeEndObject(); generator.writeEndObject();
} }
parser = xcontentType().xContent().createParser(NamedXContentRegistry.EMPTY, os.toByteArray()); parser = xcontentType().xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, os.toByteArray());
assertEquals(Token.START_OBJECT, parser.nextToken()); assertEquals(Token.START_OBJECT, parser.nextToken());
assertEquals(Token.FIELD_NAME, parser.nextToken()); assertEquals(Token.FIELD_NAME, parser.nextToken());
assertEquals("test", parser.currentName()); assertEquals("test", parser.currentName());
@ -831,7 +834,8 @@ public abstract class BaseXContentTestCase extends ESTestCase {
generator.flush(); generator.flush();
byte[] serialized = os.toByteArray(); byte[] serialized = os.toByteArray();
XContentParser parser = xcontentType().xContent().createParser(NamedXContentRegistry.EMPTY, serialized); XContentParser parser = xcontentType().xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, serialized);
Map<String, Object> map = parser.map(); Map<String, Object> map = parser.map();
assertEquals("bar", map.get("foo")); assertEquals("bar", map.get("foo"));
assertEquals(bigInteger, map.get("bigint")); assertEquals(bigInteger, map.get("bigint"));
@ -1030,7 +1034,8 @@ public abstract class BaseXContentTestCase extends ESTestCase {
assertEquals("Unknown namedObject category [java.lang.String]", e.getMessage()); assertEquals("Unknown namedObject category [java.lang.String]", e.getMessage());
} }
{ {
XContentParser emptyRegistryParser = xcontentType().xContent().createParser(NamedXContentRegistry.EMPTY, new byte[] {}); XContentParser emptyRegistryParser = xcontentType().xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, new byte[] {});
Exception e = expectThrows(ElasticsearchException.class, Exception e = expectThrows(ElasticsearchException.class,
() -> emptyRegistryParser.namedObject(String.class, "doesn't matter", null)); () -> emptyRegistryParser.namedObject(String.class, "doesn't matter", null));
assertEquals("namedObject is not supported for this parser", e.getMessage()); assertEquals("namedObject is not supported for this parser", e.getMessage());

View File

@ -32,6 +32,7 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -159,7 +160,8 @@ public class ShardSearchTransportRequestTests extends AbstractSearchTestCase {
public QueryBuilder aliasFilter(IndexMetaData indexMetaData, String... aliasNames) { public QueryBuilder aliasFilter(IndexMetaData indexMetaData, String... aliasNames) {
CheckedFunction<byte[], QueryBuilder, IOException> filterParser = bytes -> { CheckedFunction<byte[], QueryBuilder, IOException> filterParser = bytes -> {
try (XContentParser parser = XContentFactory.xContent(bytes).createParser(xContentRegistry(), bytes)) { try (XContentParser parser = XContentFactory.xContent(bytes)
.createParser(xContentRegistry(), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes)) {
return parseInnerQueryBuilder(parser); return parseInnerQueryBuilder(parser);
} }
}; };

View File

@ -22,6 +22,7 @@ package org.elasticsearch.search.suggest;
import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.text.Text; import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContent;
@ -174,7 +175,8 @@ public class SuggestionTests extends ESTestCase {
+ "\"collate_match\":true}]" + "\"collate_match\":true}]"
+ "}]" + "}]"
+ "}"; + "}";
try (XContentParser parser = xContent.createParser(xContentRegistry(), suggestionString)) { try (XContentParser parser = xContent.createParser(xContentRegistry(),
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, suggestionString)) {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation); ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation); ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.nextToken(), parser::getTokenLocation); ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.nextToken(), parser::getTokenLocation);

View File

@ -53,6 +53,7 @@ import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -404,8 +405,9 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
BytesStreamOutput out = new BytesStreamOutput(); BytesStreamOutput out = new BytesStreamOutput();
try ( try (
XContentGenerator generator = XContentType.JSON.xContent().createGenerator(out); XContentGenerator generator = XContentType.JSON.xContent().createGenerator(out);
XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, query); XContentParser parser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, query);
) { ) {
int objectIndex = -1; int objectIndex = -1;
Deque<String> levels = new LinkedList<>(); Deque<String> levels = new LinkedList<>();

View File

@ -23,6 +23,7 @@ import org.apache.http.client.methods.HttpHead;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -114,7 +115,8 @@ public class ClientYamlTestResponse {
} else { } else {
//if the body is in a binary format and gets requested as a string (e.g. to log a test failure), we convert it to json //if the body is in a binary format and gets requested as a string (e.g. to log a test failure), we convert it to json
try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) { try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
try (XContentParser parser = bodyContentType.xContent().createParser(NamedXContentRegistry.EMPTY, body)) { try (XContentParser parser = bodyContentType.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, body)) {
jsonBuilder.copyCurrentStructure(parser); jsonBuilder.copyCurrentStructure(parser);
} }
bodyAsString = jsonBuilder.string(); bodyAsString = jsonBuilder.string();

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -128,7 +129,8 @@ public class DoSection implements ExecutableSection {
} else if (token.isValue()) { } else if (token.isValue()) {
if ("body".equals(paramName)) { if ("body".equals(paramName)) {
String body = parser.text(); String body = parser.text();
XContentParser bodyParser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, body); XContentParser bodyParser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, body);
//multiple bodies are supported e.g. in case of bulk provided as a whole string //multiple bodies are supported e.g. in case of bulk provided as a whole string
while(bodyParser.nextToken() != null) { while(bodyParser.nextToken() != null) {
apiCallSection.addBody(bodyParser.mapOrdered()); apiCallSection.addBody(bodyParser.mapOrdered());