From 3b6af15a6068ffffed2a7ba1309c9cc3b19d5388 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 30 Jan 2018 18:21:10 -0500 Subject: [PATCH] XContent: Factor deprecation handling into callback (#28449) Factors the way in which XContent parsing handles deprecated fields into a callback that is set at parser construction time. The goals here are: 1. Remove Log4J as a dependency of XContent so that XContent can be used by clients without forcing log4j and our particular deprecation handling scheme. 2. Simplify handling of deprecated fields in tests. Now tests can listen directly for the deprecation callback rather than digging through a ThreadLocal. More accurately, this change begins this work. It deprecates a number of methods, pointing folks to the new versions of those methods that take `DeprecationHandler`. The plan is to slowly drop these deprecated methods. Once they are entirely removed we can remove Log4j as dependency of XContent. --- .../ingest/common/ScriptProcessor.java | 5 +- .../org/elasticsearch/common/ParseField.java | 37 ++++++--- .../common/settings/Setting.java | 6 +- .../common/settings/Settings.java | 5 +- .../common/xcontent/DeprecationHandler.java | 60 ++++++++++++++ .../xcontent/LoggingDeprecationHandler.java | 60 ++++++++++++++ .../common/xcontent/ObjectParser.java | 13 +-- .../common/xcontent/XContent.java | 83 +++++++++++++++++-- .../common/xcontent/XContentParser.java | 8 +- .../common/xcontent/cbor/CborXContent.java | 31 ++++--- .../xcontent/cbor/CborXContentParser.java | 7 +- .../common/xcontent/json/JsonXContent.java | 31 ++++--- .../xcontent/json/JsonXContentParser.java | 6 +- .../common/xcontent/smile/SmileXContent.java | 31 ++++--- .../xcontent/smile/SmileXContentParser.java | 7 +- .../support/AbstractXContentParser.java | 10 ++- .../common/xcontent/yaml/YamlXContent.java | 31 ++++--- .../xcontent/yaml/YamlXContentParser.java | 7 +- 18 files changed, 349 insertions(+), 89 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/common/xcontent/DeprecationHandler.java create mode 100644 server/src/main/java/org/elasticsearch/common/xcontent/LoggingDeprecationHandler.java diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java index bc8aa6b04a9..92bcd8f9b1e 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java @@ -23,6 +23,8 @@ import com.fasterxml.jackson.core.JsonFactory; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.json.JsonXContentParser; import org.elasticsearch.ingest.AbstractProcessor; @@ -95,8 +97,7 @@ public final class ScriptProcessor extends AbstractProcessor { public ScriptProcessor create(Map registry, String processorTag, Map config) throws Exception { XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(config); - JsonXContentParser parser = new JsonXContentParser(NamedXContentRegistry.EMPTY, - JSON_FACTORY.createParser(builder.bytes().streamInput())); + XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, builder.bytes().streamInput()); Script script = Script.parse(parser); Arrays.asList("id", "source", "inline", "lang", "params", "options").forEach(config::remove); diff --git a/server/src/main/java/org/elasticsearch/common/ParseField.java b/server/src/main/java/org/elasticsearch/common/ParseField.java index fc9377eeb2f..2f85f2dc78b 100644 --- a/server/src/main/java/org/elasticsearch/common/ParseField.java +++ b/server/src/main/java/org/elasticsearch/common/ParseField.java @@ -20,6 +20,9 @@ package org.elasticsearch.common; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.xcontent.DeprecationHandler; +import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; +import org.elasticsearch.common.xcontent.XContentParser; import java.util.Collections; import java.util.HashSet; @@ -31,9 +34,6 @@ import java.util.Set; * variants, which may be deprecated. */ public class ParseField { - - private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(ParseField.class)); - private final String name; private final String[] deprecatedNames; private String allReplacedWith = null; @@ -99,12 +99,31 @@ public class ParseField { } /** + * Does {@code fieldName} match this field? Uses {@link LoggingDeprecationHandler} + * to prevent us from having to touch every call to {@code match} in the change + * that introduced {@linkplain LoggingDeprecationHandler}. In a followup this will + * be removed. * @param fieldName * the field name to match against this {@link ParseField} * @return true if fieldName matches any of the acceptable * names for this {@link ParseField}. + * @deprecated Use {@link #match(String, DeprecationHandler)} with + * {@link XContentParser#getDeprecationHandler()} instead. */ + @Deprecated public boolean match(String fieldName) { + return match(fieldName, LoggingDeprecationHandler.INSTANCE); + } + + /** + * Does {@code fieldName} match this field? + * @param fieldName + * the field name to match against this {@link ParseField} + * @param deprecationHandler called if {@code fieldName} is deprecated + * @return true if fieldName matches any of the acceptable + * names for this {@link ParseField}. + */ + public boolean match(String fieldName, DeprecationHandler deprecationHandler) { Objects.requireNonNull(fieldName, "fieldName cannot be null"); // if this parse field has not been completely deprecated then try to // match the preferred name @@ -114,17 +133,13 @@ public class ParseField { // Now try to match against one of the deprecated names. Note that if // the parse field is entirely deprecated (allReplacedWith != null) all // fields will be in the deprecatedNames array - String msg; for (String depName : deprecatedNames) { if (fieldName.equals(depName)) { - msg = "Deprecated field [" + fieldName + "] used, expected [" + name + "] instead"; - if (allReplacedWith != null) { - // If the field is entirely deprecated then there is no - // preferred name so instead use the `allReplaceWith` - // message to indicate what should be used instead - msg = "Deprecated field [" + fieldName + "] used, replaced by [" + allReplacedWith + "]"; + if (allReplacedWith == null) { + deprecationHandler.usedDeprecatedName(fieldName, name); + } else { + deprecationHandler.usedDeprecatedField(fieldName, allReplacedWith); } - DEPRECATION_LOGGER.deprecated(msg); return true; } } diff --git a/server/src/main/java/org/elasticsearch/common/settings/Setting.java b/server/src/main/java/org/elasticsearch/common/settings/Setting.java index f7f67e424cc..65a16d974a7 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/Setting.java +++ b/server/src/main/java/org/elasticsearch/common/settings/Setting.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.MemorySizeValue; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -1143,8 +1144,9 @@ public class Setting implements ToXContentObject { } private static List parseableStringToList(String parsableString) { - // EMPTY is safe here because we never call namedObject - try (XContentParser xContentParser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, parsableString)) { + // fromXContent doesn't use named xcontent or deprecation. + try (XContentParser xContentParser = XContentType.JSON.xContent() + .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, parsableString)) { XContentParser.Token token = xContentParser.nextToken(); if (token != XContentParser.Token.START_ARRAY) { throw new IllegalArgumentException("expected START_ARRAY but got " + token); diff --git a/server/src/main/java/org/elasticsearch/common/settings/Settings.java b/server/src/main/java/org/elasticsearch/common/settings/Settings.java index c9a4c0f796b..e832f629fd4 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -37,6 +37,7 @@ import org.elasticsearch.common.unit.MemorySizeValue; import org.elasticsearch.common.unit.RatioValue; import org.elasticsearch.common.unit.SizeValue; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -1144,7 +1145,9 @@ public final class Settings implements ToXContentFragment { } else { throw new IllegalArgumentException("unable to detect content type from resource name [" + resourceName + "]"); } - try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, is)) { + // fromXContent doesn't use named xcontent or deprecation. + try (XContentParser parser = XContentFactory.xContent(xContentType) + .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, is)) { if (parser.currentToken() == null) { if (parser.nextToken() == null) { return this; // empty file diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/DeprecationHandler.java b/server/src/main/java/org/elasticsearch/common/xcontent/DeprecationHandler.java new file mode 100644 index 00000000000..1b0dcf45680 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/common/xcontent/DeprecationHandler.java @@ -0,0 +1,60 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common.xcontent; + +/** + * Callback for notifying the creator of the {@link XContentParser} that + * parsing hit a deprecated field. + */ +public interface DeprecationHandler { + /** + * Throws an {@link UnsupportedOperationException} when parsing hits a + * deprecated field. Use this when creating an {@link XContentParser} + * that won't interact with deprecation logic at all or when you want + * to fail fast when parsing deprecated fields. + */ + DeprecationHandler THROW_UNSUPPORTED_OPERATION = new DeprecationHandler() { + @Override + public void usedDeprecatedField(String usedName, String replacedWith) { + throw new UnsupportedOperationException("deprecated fields not supported here but got [" + + usedName + "] which is a deprecated name for [" + replacedWith + "]"); + } + @Override + public void usedDeprecatedName(String usedName, String modernName) { + throw new UnsupportedOperationException("deprecated fields not supported here but got [" + + usedName + "] which has been replaced with [" + modernName + "]"); + } + }; + + /** + * Called when the provided field name matches a deprecated name for the field. + * @param usedName the provided field name + * @param modernName the modern name for the field + */ + void usedDeprecatedName(String usedName, String modernName); + + /** + * Called when the provided field name matches the current field but the entire + * field has been marked as deprecated. + * @param usedName the provided field name + * @param replacedWith the name of the field that replaced this field + */ + void usedDeprecatedField(String usedName, String replacedWith); +} diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/LoggingDeprecationHandler.java b/server/src/main/java/org/elasticsearch/common/xcontent/LoggingDeprecationHandler.java new file mode 100644 index 00000000000..e075fb1711d --- /dev/null +++ b/server/src/main/java/org/elasticsearch/common/xcontent/LoggingDeprecationHandler.java @@ -0,0 +1,60 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common.xcontent; + +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.common.logging.Loggers; + +/** + * Logs deprecations to the {@link DeprecationLogger}. + *

+ * This is core's primary implementation of {@link DeprecationHandler} and + * should absolutely be used everywhere where it parses + * requests. It is much less appropriate when parsing responses from external + * sources because it will report deprecated fields back to the user as + * though the user sent them. + */ +public class LoggingDeprecationHandler implements DeprecationHandler { + public static LoggingDeprecationHandler INSTANCE = new LoggingDeprecationHandler(); + /** + * The logger to which to send deprecation messages. + * + * This uses ParseField's logger because that is the logger that + * we have been using for many releases for deprecated fields. + * Changing that will require some research to make super duper + * sure it is safe. + */ + private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(ParseField.class)); + + private LoggingDeprecationHandler() { + // Singleton + } + + @Override + public void usedDeprecatedName(String usedName, String modernName) { + DEPRECATION_LOGGER.deprecated("Deprecated field [{}] used, expected [{}] instead", usedName, modernName); + } + + @Override + public void usedDeprecatedField(String usedName, String replacedWith) { + DEPRECATION_LOGGER.deprecated("Deprecated field [{}] used, replaced by [{}]", usedName, replacedWith); + } +} diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java b/server/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java index 0b15baf1337..aa5a7e8391b 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java @@ -165,7 +165,7 @@ public final class ObjectParser extends AbstractObjectParser extends AbstractObjectParser * XContentType xContentType = XContentType.JSON; - * XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, "{\"key\" : \"value\"}"); + * XContentParser parser = xContentType.xContent().createParser( + * NamedXContentRegistry.EMPTY, ParserField."{\"key\" : \"value\"}"); * */ public interface XContentParser extends Releasable { @@ -277,4 +278,9 @@ public interface XContentParser extends Releasable { NamedXContentRegistry getXContentRegistry(); boolean isClosed(); + + /** + * The callback to notify when parsing encounters a deprecated field. + */ + DeprecationHandler getDeprecationHandler(); } diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContent.java b/server/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContent.java index 56435fd364b..f05b38fb20e 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContent.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContent.java @@ -26,6 +26,7 @@ import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.FastStringReader; +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -79,33 +80,39 @@ public class CborXContent implements XContent { } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException { - return new CborXContentParser(xContentRegistry, cborFactory.createParser(new FastStringReader(content))); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, String content) throws IOException { + return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(new FastStringReader(content))); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException { - return new CborXContentParser(xContentRegistry, cborFactory.createParser(is)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, InputStream is) throws IOException { + return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(is)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException { - return new CborXContentParser(xContentRegistry, cborFactory.createParser(data)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, byte[] data) throws IOException { + return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(data)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException { - return new CborXContentParser(xContentRegistry, cborFactory.createParser(data, offset, length)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, byte[] data, int offset, int length) throws IOException { + return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(data, offset, length)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException { - return createParser(xContentRegistry, bytes.streamInput()); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException { + return createParser(xContentRegistry, deprecationHandler, bytes.streamInput()); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException { - return new CborXContentParser(xContentRegistry, cborFactory.createParser(reader)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, Reader reader) throws IOException { + return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(reader)); } } diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContentParser.java b/server/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContentParser.java index 61b4886420f..c2f3c0fe498 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContentParser.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContentParser.java @@ -20,15 +20,16 @@ package org.elasticsearch.common.xcontent.cbor; import com.fasterxml.jackson.core.JsonParser; - +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContentParser; public class CborXContentParser extends JsonXContentParser { - public CborXContentParser(NamedXContentRegistry xContentRegistry, JsonParser parser) { - super(xContentRegistry, parser); + public CborXContentParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, JsonParser parser) { + super(xContentRegistry, deprecationHandler, parser); } @Override diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java b/server/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java index 2e4393723e0..7f5174d2722 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java @@ -25,6 +25,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.FastStringReader; +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -80,32 +81,38 @@ public class JsonXContent implements XContent { } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException { - return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(new FastStringReader(content))); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, String content) throws IOException { + return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(new FastStringReader(content))); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException { - return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(is)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, InputStream is) throws IOException { + return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(is)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException { - return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(data)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, byte[] data) throws IOException { + return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(data)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException { - return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(data, offset, length)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, byte[] data, int offset, int length) throws IOException { + return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(data, offset, length)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException { - return createParser(xContentRegistry, bytes.streamInput()); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException { + return createParser(xContentRegistry, deprecationHandler, bytes.streamInput()); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException { - return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(reader)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, Reader reader) throws IOException { + return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(reader)); } } diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java b/server/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java index e5c30208ed6..d1075dd0173 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentParser.java @@ -25,6 +25,7 @@ import com.fasterxml.jackson.core.JsonToken; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.common.xcontent.XContentType; @@ -37,8 +38,9 @@ public class JsonXContentParser extends AbstractXContentParser { final JsonParser parser; - public JsonXContentParser(NamedXContentRegistry xContentRegistry, JsonParser parser) { - super(xContentRegistry); + public JsonXContentParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, JsonParser parser) { + super(xContentRegistry, deprecationHandler); this.parser = parser; } diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java b/server/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java index b43a13a9193..17de93d87ba 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java @@ -26,6 +26,7 @@ import com.fasterxml.jackson.dataformat.smile.SmileFactory; import com.fasterxml.jackson.dataformat.smile.SmileGenerator; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.FastStringReader; +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -80,32 +81,38 @@ public class SmileXContent implements XContent { } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException { - return new SmileXContentParser(xContentRegistry, smileFactory.createParser(new FastStringReader(content))); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, String content) throws IOException { + return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(new FastStringReader(content))); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException { - return new SmileXContentParser(xContentRegistry, smileFactory.createParser(is)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, InputStream is) throws IOException { + return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(is)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException { - return new SmileXContentParser(xContentRegistry, smileFactory.createParser(data)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, byte[] data) throws IOException { + return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(data)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException { - return new SmileXContentParser(xContentRegistry, smileFactory.createParser(data, offset, length)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, byte[] data, int offset, int length) throws IOException { + return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(data, offset, length)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException { - return createParser(xContentRegistry, bytes.streamInput()); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException { + return createParser(xContentRegistry, deprecationHandler, bytes.streamInput()); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException { - return new SmileXContentParser(xContentRegistry, smileFactory.createParser(reader)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, Reader reader) throws IOException { + return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(reader)); } } diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContentParser.java b/server/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContentParser.java index c7b4b8c000c..58cb50c0534 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContentParser.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContentParser.java @@ -20,15 +20,16 @@ package org.elasticsearch.common.xcontent.smile; import com.fasterxml.jackson.core.JsonParser; - +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContentParser; public class SmileXContentParser extends JsonXContentParser { - public SmileXContentParser(NamedXContentRegistry xContentRegistry, JsonParser parser) { - super(xContentRegistry, parser); + public SmileXContentParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, JsonParser parser) { + super(xContentRegistry, deprecationHandler, parser); } @Override diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java b/server/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java index 9aae1ca396c..6d41c5b83da 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java @@ -23,6 +23,7 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Numbers; +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentParser; @@ -52,9 +53,11 @@ public abstract class AbstractXContentParser implements XContentParser { } private final NamedXContentRegistry xContentRegistry; + private final DeprecationHandler deprecationHandler; - public AbstractXContentParser(NamedXContentRegistry xContentRegistry) { + public AbstractXContentParser(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler) { this.xContentRegistry = xContentRegistry; + this.deprecationHandler = deprecationHandler; } // The 3rd party parsers we rely on are known to silently truncate fractions: see @@ -409,4 +412,9 @@ public abstract class AbstractXContentParser implements XContentParser { @Override public abstract boolean isClosed(); + + @Override + public DeprecationHandler getDeprecationHandler() { + return deprecationHandler; + } } diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/yaml/YamlXContent.java b/server/src/main/java/org/elasticsearch/common/xcontent/yaml/YamlXContent.java index 56dda843c45..3547440eb8b 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/yaml/YamlXContent.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/yaml/YamlXContent.java @@ -25,6 +25,7 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.FastStringReader; +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -75,32 +76,38 @@ public class YamlXContent implements XContent { } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException { - return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(new FastStringReader(content))); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, String content) throws IOException { + return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(new FastStringReader(content))); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException { - return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(is)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, InputStream is) throws IOException { + return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(is)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException { - return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(data)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, byte[] data) throws IOException { + return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(data)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException { - return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(data, offset, length)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, byte[] data, int offset, int length) throws IOException { + return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(data, offset, length)); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException { - return createParser(xContentRegistry, bytes.streamInput()); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException { + return createParser(xContentRegistry, deprecationHandler, bytes.streamInput()); } @Override - public XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException { - return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(reader)); + public XContentParser createParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, Reader reader) throws IOException { + return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(reader)); } } diff --git a/server/src/main/java/org/elasticsearch/common/xcontent/yaml/YamlXContentParser.java b/server/src/main/java/org/elasticsearch/common/xcontent/yaml/YamlXContentParser.java index c2fdcfa740b..f03094b862e 100644 --- a/server/src/main/java/org/elasticsearch/common/xcontent/yaml/YamlXContentParser.java +++ b/server/src/main/java/org/elasticsearch/common/xcontent/yaml/YamlXContentParser.java @@ -20,15 +20,16 @@ package org.elasticsearch.common.xcontent.yaml; import com.fasterxml.jackson.core.JsonParser; - +import org.elasticsearch.common.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContentParser; public class YamlXContentParser extends JsonXContentParser { - public YamlXContentParser(NamedXContentRegistry xContentRegistry, JsonParser parser) { - super(xContentRegistry, parser); + public YamlXContentParser(NamedXContentRegistry xContentRegistry, + DeprecationHandler deprecationHandler, JsonParser parser) { + super(xContentRegistry, deprecationHandler, parser); } @Override