Remove deprecated createParser methods (#28697)
* 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
This commit is contained in:
parent
5aeb479ffd
commit
0dd79028c9
|
@ -346,7 +346,8 @@ public class PercolateQueryBuilder extends AbstractQueryBuilder<PercolateQueryBu
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.elasticsearch.action.search.SearchRequest;
|
|||
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;
|
||||
|
@ -129,7 +130,8 @@ final class RemoteRequestBuilders {
|
|||
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"); {
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.elasticsearch.cluster.service.ClusterService;
|
|||
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;
|
||||
|
@ -248,7 +249,8 @@ public class TransportGetTaskAction extends HandledTransportAction<GetTaskReques
|
|||
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));
|
||||
}
|
||||
|
|
|
@ -319,7 +319,8 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
|
|||
*/
|
||||
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) {
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
|||
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;
|
||||
|
@ -436,7 +437,8 @@ public class PutIndexTemplateRequest extends MasterNodeRequest<PutIndexTemplateR
|
|||
*/
|
||||
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) {
|
||||
|
|
|
@ -115,59 +115,4 @@ public interface XContent {
|
|||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,15 +38,6 @@ import java.util.Objects;
|
|||
@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
|
||||
|
@ -63,7 +54,7 @@ public class XContentHelper {
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import com.fasterxml.jackson.core.util.JsonGeneratorDelegate;
|
|||
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;
|
||||
|
@ -316,7 +316,10 @@ public class JsonXContentGenerator implements XContentGenerator {
|
|||
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);
|
||||
|
@ -395,7 +398,9 @@ public class JsonXContentGenerator implements XContentGenerator {
|
|||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -309,7 +309,8 @@ public abstract class MetaDataStateFormat<T> {
|
|||
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) {
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
|||
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;
|
||||
|
@ -401,7 +402,9 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
|||
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) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.elasticsearch.cluster.metadata.MetaData;
|
|||
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;
|
||||
|
@ -109,7 +110,8 @@ public abstract class BlobStoreFormat<T extends ToXContent> {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue