Skip to content

Commit 3c66958

Browse files
authored
Remove deprecated xcontent method (#84314) (#84372)
This removes one of the `createParser` methods that I deprecated in #79814, migrating callers to one of the new methods that it created.
1 parent caa6605 commit 3c66958

File tree

15 files changed

+37
-97
lines changed

15 files changed

+37
-97
lines changed

distribution/tools/geoip-cli/src/test/java/org/elasticsearch/geoip/GeoIpCliTests.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
1313
import org.apache.lucene.tests.util.LuceneTestCase;
1414
import org.elasticsearch.cli.MockTerminal;
15-
import org.elasticsearch.xcontent.DeprecationHandler;
16-
import org.elasticsearch.xcontent.NamedXContentRegistry;
1715
import org.elasticsearch.xcontent.XContentParser;
16+
import org.elasticsearch.xcontent.XContentParserConfiguration;
1817
import org.elasticsearch.xcontent.XContentType;
1918

2019
import java.io.BufferedInputStream;
@@ -92,10 +91,7 @@ public void testSameDirectory() throws Exception {
9291

9392
private void verifyOverview() throws Exception {
9493
byte[] data = Files.readAllBytes(target.resolve("overview.json"));
95-
try (
96-
XContentParser parser = XContentType.JSON.xContent()
97-
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, data)
98-
) {
94+
try (XContentParser parser = XContentType.JSON.xContent().createParser(XContentParserConfiguration.EMPTY, data)) {
9995
@SuppressWarnings({ "unchecked" })
10096
List<Map<String, String>> list = (List) parser.list();
10197
assertThat(list, containsInAnyOrder(hasEntry("name", "a.tgz"), hasEntry("name", "b.tgz"), hasEntry("name", "c.tgz")));

libs/x-content/src/main/java/org/elasticsearch/xcontent/XContent.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,6 @@ default XContentParser createParser(XContentParserConfiguration config, byte[] d
7777
return createParser(config, data, 0, data.length);
7878
}
7979

80-
/**
81-
* Creates a parser over the provided bytes.
82-
* @deprecated Use {@link #createParser(XContentParserConfiguration, byte[])}
83-
*/
84-
@Deprecated
85-
default XContentParser createParser(NamedXContentRegistry registry, DeprecationHandler deprecationHandler, byte[] data)
86-
throws IOException {
87-
return createParser(XContentParserConfiguration.EMPTY.withRegistry(registry).withDeprecationHandler(deprecationHandler), data);
88-
}
89-
9080
/**
9181
* Creates a parser over the provided bytes.
9282
*/

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloader.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
import org.elasticsearch.tasks.TaskId;
3737
import org.elasticsearch.threadpool.Scheduler;
3838
import org.elasticsearch.threadpool.ThreadPool;
39-
import org.elasticsearch.xcontent.DeprecationHandler;
40-
import org.elasticsearch.xcontent.NamedXContentRegistry;
4139
import org.elasticsearch.xcontent.XContentParser;
40+
import org.elasticsearch.xcontent.XContentParserConfiguration;
4241
import org.elasticsearch.xcontent.XContentType;
4342

4443
import java.io.IOException;
@@ -141,10 +140,7 @@ private <T> List<T> fetchDatabasesOverview() throws IOException {
141140
String url = endpoint + "?elastic_geoip_service_tos=agree";
142141
logger.debug("fetching geoip databases overview from [{}]", url);
143142
byte[] data = httpClient.getBytes(url);
144-
try (
145-
XContentParser parser = XContentType.JSON.xContent()
146-
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, data)
147-
) {
143+
try (XContentParser parser = XContentType.JSON.xContent().createParser(XContentParserConfiguration.EMPTY, data)) {
148144
return (List<T>) parser.list();
149145
}
150146
}

server/src/test/java/org/elasticsearch/common/xcontent/BaseXContentTestCase.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.elasticsearch.common.util.CollectionUtils;
2525
import org.elasticsearch.core.PathUtils;
2626
import org.elasticsearch.test.ESTestCase;
27-
import org.elasticsearch.xcontent.DeprecationHandler;
2827
import org.elasticsearch.xcontent.NamedObjectNotFoundException;
2928
import org.elasticsearch.xcontent.NamedXContentRegistry;
3029
import org.elasticsearch.xcontent.ParseField;
@@ -37,6 +36,7 @@
3736
import org.elasticsearch.xcontent.XContentParseException;
3837
import org.elasticsearch.xcontent.XContentParser;
3938
import org.elasticsearch.xcontent.XContentParser.Token;
39+
import org.elasticsearch.xcontent.XContentParserConfiguration;
4040
import org.elasticsearch.xcontent.XContentType;
4141
import org.hamcrest.Matcher;
4242
import org.hamcrest.Matchers;
@@ -838,10 +838,7 @@ void doTestRawField(XContent source, boolean useStream) throws Exception {
838838
generator.writeEndObject();
839839
}
840840

841-
try (
842-
XContentParser parser = xcontentType().xContent()
843-
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, os.toByteArray())
844-
) {
841+
try (XContentParser parser = xcontentType().xContent().createParser(XContentParserConfiguration.EMPTY, os.toByteArray())) {
845842
assertEquals(Token.START_OBJECT, parser.nextToken());
846843
assertEquals(Token.FIELD_NAME, parser.nextToken());
847844
assertEquals("bar", parser.currentName());
@@ -876,10 +873,7 @@ void doTestRawValue(XContent source) throws Exception {
876873
generator.writeRawValue(new BytesArray(rawData).streamInput(), source.type());
877874
}
878875

879-
try (
880-
XContentParser parser = xcontentType().xContent()
881-
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, os.toByteArray())
882-
) {
876+
try (XContentParser parser = xcontentType().xContent().createParser(XContentParserConfiguration.EMPTY, os.toByteArray())) {
883877
assertEquals(Token.START_OBJECT, parser.nextToken());
884878
assertEquals(Token.FIELD_NAME, parser.nextToken());
885879
assertEquals("foo", parser.currentName());
@@ -903,10 +897,7 @@ public void close() {
903897
generator.writeEndObject();
904898
}
905899

906-
try (
907-
XContentParser parser = xcontentType().xContent()
908-
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, os.toByteArray())
909-
) {
900+
try (XContentParser parser = xcontentType().xContent().createParser(XContentParserConfiguration.EMPTY, os.toByteArray())) {
910901
assertEquals(Token.START_OBJECT, parser.nextToken());
911902
assertEquals(Token.FIELD_NAME, parser.nextToken());
912903
assertEquals("test", parser.currentName());
@@ -935,10 +926,7 @@ protected void doTestBigInteger(JsonGenerator generator, ByteArrayOutputStream o
935926
generator.flush();
936927
byte[] serialized = os.toByteArray();
937928

938-
try (
939-
XContentParser parser = xcontentType().xContent()
940-
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, serialized)
941-
) {
929+
try (XContentParser parser = xcontentType().xContent().createParser(XContentParserConfiguration.EMPTY, serialized)) {
942930
Map<String, Object> map = parser.map();
943931
assertEquals("bar", map.get("foo"));
944932
assertEquals(bigInteger, map.get("bigint"));
@@ -1140,8 +1128,7 @@ public void testNamedObject() throws IOException {
11401128
}
11411129
}
11421130
try (
1143-
XContentParser emptyRegistryParser = xcontentType().xContent()
1144-
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, new byte[] {})
1131+
XContentParser emptyRegistryParser = xcontentType().xContent().createParser(XContentParserConfiguration.EMPTY, new byte[] {})
11451132
) {
11461133
Exception e = expectThrows(
11471134
XContentParseException.class,

test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
import org.elasticsearch.client.Response;
1414
import org.elasticsearch.common.Strings;
1515
import org.elasticsearch.common.bytes.BytesArray;
16-
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
17-
import org.elasticsearch.xcontent.NamedXContentRegistry;
1816
import org.elasticsearch.xcontent.XContentBuilder;
1917
import org.elasticsearch.xcontent.XContentFactory;
2018
import org.elasticsearch.xcontent.XContentParser;
19+
import org.elasticsearch.xcontent.XContentParserConfiguration;
2120
import org.elasticsearch.xcontent.XContentType;
2221

2322
import java.io.IOException;
@@ -129,10 +128,7 @@ public String getBodyAsString() {
129128
} else {
130129
// 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
131130
try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
132-
try (
133-
XContentParser parser = bodyContentType.xContent()
134-
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, body)
135-
) {
131+
try (XContentParser parser = bodyContentType.xContent().createParser(XContentParserConfiguration.EMPTY, body)) {
136132
jsonBuilder.copyCurrentStructure(parser);
137133
}
138134
bodyAsString = Strings.toString(jsonBuilder);

x-pack/plugin/core/src/javaRestTest/java/org/elasticsearch/xpack/core/DataStreamRestIT.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
import org.elasticsearch.common.settings.Settings;
1414
import org.elasticsearch.common.util.concurrent.ThreadContext;
1515
import org.elasticsearch.test.rest.ESRestTestCase;
16-
import org.elasticsearch.xcontent.DeprecationHandler;
17-
import org.elasticsearch.xcontent.NamedXContentRegistry;
1816
import org.elasticsearch.xcontent.XContentParser;
17+
import org.elasticsearch.xcontent.XContentParserConfiguration;
1918
import org.elasticsearch.xcontent.json.JsonXContent;
2019

2120
import java.util.Map;
@@ -72,8 +71,7 @@ public Map<String, Object> getLocation(String path) {
7271
Response executeRepsonse = client().performRequest(new Request("GET", path));
7372
try (
7473
XContentParser parser = JsonXContent.jsonXContent.createParser(
75-
NamedXContentRegistry.EMPTY,
76-
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
74+
XContentParserConfiguration.EMPTY,
7775
EntityUtils.toByteArray(executeRepsonse.getEntity())
7876
)
7977
) {

x-pack/plugin/core/src/main/java/org/elasticsearch/license/SelfGeneratedLicense.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88

99
import org.elasticsearch.cluster.node.DiscoveryNodes;
1010
import org.elasticsearch.common.bytes.BytesReference;
11-
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
12-
import org.elasticsearch.xcontent.NamedXContentRegistry;
1311
import org.elasticsearch.xcontent.ToXContent;
1412
import org.elasticsearch.xcontent.XContentBuilder;
1513
import org.elasticsearch.xcontent.XContentFactory;
1614
import org.elasticsearch.xcontent.XContentParser;
15+
import org.elasticsearch.xcontent.XContentParserConfiguration;
1716
import org.elasticsearch.xcontent.XContentType;
1817

1918
import java.io.IOException;
@@ -69,7 +68,7 @@ public static boolean verify(final License license) {
6968
// EMPTY is safe here because we don't call namedObject
7069
try (
7170
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
72-
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, decryptedContent)
71+
.createParser(XContentParserConfiguration.EMPTY, decryptedContent)
7372
) {
7473
parser.nextToken();
7574
expectedLicense = License.builder()

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditor.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
1919
import org.elasticsearch.cluster.service.ClusterService;
2020
import org.elasticsearch.core.TimeValue;
21-
import org.elasticsearch.xcontent.DeprecationHandler;
22-
import org.elasticsearch.xcontent.NamedXContentRegistry;
2321
import org.elasticsearch.xcontent.ToXContent;
2422
import org.elasticsearch.xcontent.XContentBuilder;
23+
import org.elasticsearch.xcontent.XContentParserConfiguration;
2524
import org.elasticsearch.xcontent.json.JsonXContent;
2625
import org.elasticsearch.xpack.core.ml.utils.MlIndexAndAlias;
2726
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
@@ -70,11 +69,7 @@ protected AbstractAuditor(
7069
try {
7170
return new PutComposableIndexTemplateAction.Request(templateConfig.getTemplateName()).indexTemplate(
7271
ComposableIndexTemplate.parse(
73-
JsonXContent.jsonXContent.createParser(
74-
NamedXContentRegistry.EMPTY,
75-
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
76-
templateConfig.loadBytes()
77-
)
72+
JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, templateConfig.loadBytes())
7873
)
7974
).masterNodeTimeout(MASTER_TIMEOUT);
8075
} catch (IOException e) {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
import org.elasticsearch.core.TimeValue;
3333
import org.elasticsearch.index.Index;
3434
import org.elasticsearch.indices.SystemIndexDescriptor;
35-
import org.elasticsearch.xcontent.DeprecationHandler;
36-
import org.elasticsearch.xcontent.NamedXContentRegistry;
35+
import org.elasticsearch.xcontent.XContentParserConfiguration;
3736
import org.elasticsearch.xcontent.json.JsonXContent;
3837
import org.elasticsearch.xpack.core.template.IndexTemplateConfig;
3938

@@ -333,11 +332,7 @@ public static void installIndexTemplateIfRequired(
333332
try {
334333
request = new PutComposableIndexTemplateAction.Request(templateConfig.getTemplateName()).indexTemplate(
335334
ComposableIndexTemplate.parse(
336-
JsonXContent.jsonXContent.createParser(
337-
NamedXContentRegistry.EMPTY,
338-
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
339-
templateConfig.loadBytes()
340-
)
335+
JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, templateConfig.loadBytes())
341336
)
342337
).masterNodeTimeout(masterTimeout);
343338
} catch (IOException e) {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/EnrollmentToken.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010
import org.elasticsearch.common.Strings;
1111
import org.elasticsearch.xcontent.ConstructingObjectParser;
12-
import org.elasticsearch.xcontent.DeprecationHandler;
13-
import org.elasticsearch.xcontent.NamedXContentRegistry;
1412
import org.elasticsearch.xcontent.ParseField;
1513
import org.elasticsearch.xcontent.XContentBuilder;
1614
import org.elasticsearch.xcontent.XContentParser;
15+
import org.elasticsearch.xcontent.XContentParserConfiguration;
1716
import org.elasticsearch.xcontent.json.JsonXContent;
1817

1918
import java.io.IOException;
@@ -111,8 +110,7 @@ public static EnrollmentToken decodeFromString(String encoded) throws IOExceptio
111110
throw new IOException("Cannot decode enrollment token from an empty string");
112111
}
113112
final XContentParser jsonParser = JsonXContent.jsonXContent.createParser(
114-
NamedXContentRegistry.EMPTY,
115-
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
113+
XContentParserConfiguration.EMPTY,
116114
Base64.getDecoder().decode(encoded)
117115
);
118116
return EnrollmentToken.PARSER.parse(jsonParser, null);

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/privilege/ConfigurableClusterPrivilegesTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,18 @@
1212
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1313
import org.elasticsearch.common.io.stream.StreamInput;
1414
import org.elasticsearch.test.ESTestCase;
15-
import org.elasticsearch.xcontent.NamedXContentRegistry;
1615
import org.elasticsearch.xcontent.ToXContent;
1716
import org.elasticsearch.xcontent.XContent;
1817
import org.elasticsearch.xcontent.XContentBuilder;
1918
import org.elasticsearch.xcontent.XContentParser;
19+
import org.elasticsearch.xcontent.XContentParserConfiguration;
2020
import org.elasticsearch.xcontent.XContentType;
2121
import org.elasticsearch.xpack.core.XPackClientPlugin;
2222

2323
import java.io.ByteArrayOutputStream;
2424
import java.util.Arrays;
2525
import java.util.List;
2626

27-
import static org.elasticsearch.xcontent.DeprecationHandler.THROW_UNSUPPORTED_OPERATION;
2827
import static org.hamcrest.Matchers.equalTo;
2928

3029
public class ConfigurableClusterPrivilegesTests extends ESTestCase {
@@ -52,7 +51,7 @@ public void testGenerateAndParseXContent() throws Exception {
5251
builder.flush();
5352

5453
final byte[] bytes = out.toByteArray();
55-
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, bytes)) {
54+
try (XContentParser parser = xContent.createParser(XContentParserConfiguration.EMPTY, bytes)) {
5655
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
5756
final List<ConfigurableClusterPrivilege> clone = ConfigurableClusterPrivileges.parse(parser);
5857
assertThat(clone, equalTo(original));

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/privilege/ManageApplicationPrivilegesTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
import org.elasticsearch.common.util.set.Sets;
1515
import org.elasticsearch.test.ESTestCase;
1616
import org.elasticsearch.test.EqualsHashCodeTestUtils;
17-
import org.elasticsearch.xcontent.NamedXContentRegistry;
1817
import org.elasticsearch.xcontent.ToXContent;
1918
import org.elasticsearch.xcontent.XContent;
2019
import org.elasticsearch.xcontent.XContentBuilder;
2120
import org.elasticsearch.xcontent.XContentParser;
21+
import org.elasticsearch.xcontent.XContentParserConfiguration;
2222
import org.elasticsearch.xcontent.XContentType;
2323
import org.elasticsearch.xpack.core.XPackClientPlugin;
2424
import org.elasticsearch.xpack.core.security.action.privilege.DeletePrivilegesRequest;
@@ -37,7 +37,6 @@
3737
import java.util.Locale;
3838
import java.util.Set;
3939

40-
import static org.elasticsearch.xcontent.DeprecationHandler.THROW_UNSUPPORTED_OPERATION;
4140
import static org.hamcrest.Matchers.equalTo;
4241
import static org.hamcrest.Matchers.notNullValue;
4342
import static org.hamcrest.Matchers.nullValue;
@@ -70,7 +69,7 @@ public void testGenerateAndParseXContent() throws Exception {
7069
builder.flush();
7170

7271
final byte[] bytes = out.toByteArray();
73-
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, bytes)) {
72+
try (XContentParser parser = xContent.createParser(XContentParserConfiguration.EMPTY, bytes)) {
7473
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
7574
// ManageApplicationPrivileges.parse requires that the parser be positioned on the "manage" field.
7675
assertThat(parser.nextToken(), equalTo(XContentParser.Token.FIELD_NAME));

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/privilege/WriteProfileDataPrivilegesTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.xcontent.XContentBuilder;
2525
import org.elasticsearch.xcontent.XContentParseException;
2626
import org.elasticsearch.xcontent.XContentParser;
27+
import org.elasticsearch.xcontent.XContentParserConfiguration;
2728
import org.elasticsearch.xcontent.XContentType;
2829
import org.elasticsearch.xpack.core.XPackClientPlugin;
2930
import org.elasticsearch.xpack.core.security.action.profile.ActivateProfileAction;
@@ -43,7 +44,6 @@
4344
import java.util.Map;
4445
import java.util.Set;
4546

46-
import static org.elasticsearch.xcontent.DeprecationHandler.THROW_UNSUPPORTED_OPERATION;
4747
import static org.hamcrest.Matchers.equalTo;
4848
import static org.hamcrest.Matchers.is;
4949
import static org.hamcrest.Matchers.notNullValue;
@@ -77,7 +77,7 @@ public void testGenerateAndParseXContent() throws Exception {
7777
builder.flush();
7878

7979
final byte[] bytes = out.toByteArray();
80-
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, bytes)) {
80+
try (XContentParser parser = xContent.createParser(XContentParserConfiguration.EMPTY, bytes)) {
8181
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
8282
assertThat(parser.nextToken(), equalTo(XContentParser.Token.FIELD_NAME));
8383
final ConfigurableClusterPrivileges.WriteProfileDataPrivileges clone =

0 commit comments

Comments
 (0)