Skip to content

Commit

Permalink
Remove deprecated createParser methods (#28697)
Browse files Browse the repository at this point in the history
* Remove deprecated createParser methods

This removes the final instances of the callers of `XContent.createParser` and
`XContentHelper.createParser` that did not pass in the `DeprecationHandler`. It
also removes the now-unused deprecated methods and fully removes any mention of
Log4j or LoggingDeprecationHandler from the XContent code.

Relates to #28504

* Add comments in JsonXContentGenerator
  • Loading branch information
dakrone authored Feb 16, 2018
1 parent 5aeb479 commit 0dd7902
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
if (documents.isEmpty() == false) {
builder.startArray(DOCUMENTS_FIELD.getPreferredName());
for (BytesReference document : documents) {
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, document)) {
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE, document)) {
parser.nextToken();
XContentHelper.copyCurrentStructure(builder.generator(), parser);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
Expand Down Expand Up @@ -129,7 +130,8 @@ static Map<String, String> initialSearchParams(SearchRequest searchRequest, Vers
static HttpEntity initialSearchEntity(SearchRequest searchRequest, BytesReference query, Version remoteVersion) {
// EMPTY is safe here because we're not calling namedObject
try (XContentBuilder entity = JsonXContent.contentBuilder();
XContentParser queryParser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, query)) {
XContentParser queryParser = XContentHelper
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, query)) {
entity.startObject();

entity.field("query"); {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
Expand Down Expand Up @@ -248,7 +249,8 @@ void onGetFinishedTaskFromIndex(GetResponse response, ActionListener<GetTaskResp
listener.onFailure(new ElasticsearchException("Stored task status for [{}] didn't contain any source!", response.getId()));
return;
}
try (XContentParser parser = XContentHelper.createParser(xContentRegistry, response.getSourceAsBytesRef())) {
try (XContentParser parser = XContentHelper
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, response.getSourceAsBytesRef())) {
TaskResult result = TaskResult.PARSER.apply(parser, null);
listener.onResponse(new GetTaskResponse(result));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ public CreateIndexRequest aliases(String source) {
*/
public CreateIndexRequest aliases(BytesReference source) {
// EMPTY is safe here because we never call namedObject
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, source)) {
try (XContentParser parser = XContentHelper
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
//move to the first alias
parser.nextToken();
while ((parser.nextToken()) != XContentParser.Token.END_OBJECT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
Expand Down Expand Up @@ -436,7 +437,8 @@ public PutIndexTemplateRequest aliases(String source) {
*/
public PutIndexTemplateRequest aliases(BytesReference source) {
// EMPTY is safe here because we never call namedObject
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, source)) {
try (XContentParser parser = XContentHelper
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
//move to the first alias
parser.nextToken();
while ((parser.nextToken()) != XContentParser.Token.END_OBJECT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,59 +115,4 @@ XContentParser createParser(NamedXContentRegistry xContentRegistry,
*/
XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, Reader reader) throws IOException;

/**
* Creates a parser over the provided string content using
* {@link LoggingDeprecationHandler}.
* @deprecated This is a temporary shim so we can migrate all calls to createParser incrementally.
* Use {@link #createParser(NamedXContentRegistry, DeprecationHandler, String)} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, content);
}

/**
* Creates a parser over the provided input stream using
* {@link LoggingDeprecationHandler}.
* @deprecated This is a temporary shim so we can migrate all calls to createParser incrementally.
* Use {@link #createParser(NamedXContentRegistry, DeprecationHandler, InputStream)} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, is);
}

/**
* 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[])} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException {
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, BytesReference)} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, bytes);
}

/**
* Creates a parser over the provided reader using
* {@link LoggingDeprecationHandler}.
* @deprecated This is a temporary shim so we can migrate all calls to createParser incrementally.
* Use {@link #createParser(NamedXContentRegistry, DeprecationHandler, Reader)} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, reader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@
@SuppressWarnings("unchecked")
public class XContentHelper {

/**
* Creates a parser based on the bytes provided
* @deprecated this is a temporary shim and will be removed shortly
*/
@Deprecated
public static XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, bytes);
}

/**
* Creates a parser based on the bytes provided
* @deprecated use {@link #createParser(NamedXContentRegistry, DeprecationHandler, BytesReference, XContentType)} to avoid content type auto-detection
Expand All @@ -63,7 +54,7 @@ public static XContentParser createParser(NamedXContentRegistry xContentRegistry
final XContentType contentType = XContentFactory.xContentType(compressedInput);
return XContentFactory.xContent(contentType).createParser(xContentRegistry, deprecationHandler, compressedInput);
} else {
return XContentFactory.xContent(bytes).createParser(xContentRegistry, bytes.streamInput());
return XContentFactory.xContent(bytes).createParser(xContentRegistry, deprecationHandler, bytes.streamInput());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentFactory;
Expand Down Expand Up @@ -316,7 +316,10 @@ public void writeRawField(String name, InputStream content, XContentType content
if (mayWriteRawData(contentType) == false) {
// EMPTY is safe here because we never call namedObject when writing raw data
try (XContentParser parser = XContentFactory.xContent(contentType)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, content)) {
// It's okay to pass the throwing deprecation handler
// because we should not be writing raw fields when
// generating JSON
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, content)) {
parser.nextToken();
writeFieldName(name);
copyCurrentStructure(parser);
Expand Down Expand Up @@ -395,7 +398,9 @@ protected void copyRawValue(BytesReference content, XContent xContent) throws IO
// EMPTY is safe here because we never call namedObject
try (StreamInput input = content.streamInput();
XContentParser parser = xContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, input)) {
// It's okay to pass the throwing deprecation handler because we
// should not be writing raw fields when generating JSON
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, input)) {
copyCurrentStructure(parser);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ public T loadLatestState(Logger logger, NamedXContentRegistry namedXContentRegi
logger.debug("{}: no data for [{}], ignoring...", prefix, stateFile.toAbsolutePath());
continue;
}
try (XContentParser parser = XContentHelper.createParser(namedXContentRegistry, new BytesArray(data))) {
try (XContentParser parser = XContentHelper
.createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE, new BytesArray(data))) {
state = fromXContent(parser);
}
if (state == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.elasticsearch.common.geo.parsers.ShapeParser;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
Expand Down Expand Up @@ -401,7 +402,9 @@ public void onResponse(GetResponse response) {
int currentPathSlot = 0;

// It is safe to use EMPTY here because this never uses namedObject
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, response.getSourceAsBytesRef())) {
try (XContentParser parser = XContentHelper
.createParser(NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE, response.getSourceAsBytesRef())) {
XContentParser.Token currentToken;
while ((currentToken = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (currentToken == XContentParser.Token.FIELD_NAME) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.blobstore.BlobContainer;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentHelper;
Expand Down Expand Up @@ -109,7 +110,8 @@ protected String blobName(String name) {
}

protected T read(BytesReference bytes) throws IOException {
try (XContentParser parser = XContentHelper.createParser(namedXContentRegistry, bytes)) {
try (XContentParser parser = XContentHelper
.createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE, bytes)) {
T obj = reader.apply(parser);
return obj;
}
Expand Down

0 comments on commit 0dd7902

Please sign in to comment.