Skip to content

Commit 6c70578

Browse files
authored
Remove deprecated xcontent method (#84314)
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 b42f0d4 commit 6c70578

File tree

63 files changed

+226
-454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+226
-454
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/indices/PutIndexTemplateRequest.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
import org.elasticsearch.common.xcontent.XContentHelper;
1818
import org.elasticsearch.common.xcontent.support.XContentMapValues;
1919
import org.elasticsearch.core.TimeValue;
20-
import org.elasticsearch.xcontent.DeprecationHandler;
21-
import org.elasticsearch.xcontent.NamedXContentRegistry;
2220
import org.elasticsearch.xcontent.ToXContentFragment;
2321
import org.elasticsearch.xcontent.XContentBuilder;
2422
import org.elasticsearch.xcontent.XContentFactory;
2523
import org.elasticsearch.xcontent.XContentParser;
24+
import org.elasticsearch.xcontent.XContentParserConfiguration;
2625
import org.elasticsearch.xcontent.XContentType;
2726
import org.elasticsearch.xcontent.json.JsonXContent;
2827

@@ -352,13 +351,7 @@ public PutIndexTemplateRequest aliases(String source) {
352351
*/
353352
public PutIndexTemplateRequest aliases(BytesReference source) {
354353
// EMPTY is safe here because we never call namedObject
355-
try (
356-
XContentParser parser = XContentHelper.createParser(
357-
NamedXContentRegistry.EMPTY,
358-
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
359-
source
360-
)
361-
) {
354+
try (XContentParser parser = XContentHelper.createParser(XContentParserConfiguration.EMPTY, source)) {
362355
// move to the first alias
363356
parser.nextToken();
364357
while ((parser.nextToken()) != XContentParser.Token.END_OBJECT) {
@@ -413,11 +406,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
413406
if (mappings != null) {
414407
builder.field("mappings");
415408
try (
416-
XContentParser parser = JsonXContent.jsonXContent.createParser(
417-
NamedXContentRegistry.EMPTY,
418-
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
419-
mappings.utf8ToString()
420-
)
409+
XContentParser parser = JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, mappings.utf8ToString())
421410
) {
422411
builder.copyCurrentStructure(parser);
423412
}

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
@@ -55,16 +55,6 @@ default XContentGenerator createGenerator(OutputStream os) throws IOException {
5555
*/
5656
XContentParser createParser(XContentParserConfiguration config, String content) throws IOException;
5757

58-
/**
59-
* Creates a parser over the provided string content.
60-
* @deprecated Use {@link #createParser(XContentParserConfiguration, InputStream)}
61-
*/
62-
@Deprecated
63-
default XContentParser createParser(NamedXContentRegistry registry, DeprecationHandler deprecationHandler, String content)
64-
throws IOException {
65-
return createParser(XContentParserConfiguration.EMPTY.withRegistry(registry).withDeprecationHandler(deprecationHandler), content);
66-
}
67-
6858
/**
6959
* Creates a parser over the provided input stream.
7060
*/

modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TransportSearchTemplateAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.xcontent.NamedXContentRegistry;
2929
import org.elasticsearch.xcontent.XContentFactory;
3030
import org.elasticsearch.xcontent.XContentParser;
31+
import org.elasticsearch.xcontent.XContentParserConfiguration;
3132
import org.elasticsearch.xcontent.XContentType;
3233

3334
import java.io.IOException;
@@ -98,10 +99,9 @@ static SearchRequest convert(
9899
return null;
99100
}
100101

101-
try (
102-
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
103-
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, source)
104-
) {
102+
XContentParserConfiguration parserConfig = XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry)
103+
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE);
104+
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(parserConfig, source)) {
105105
SearchSourceBuilder builder = SearchSourceBuilder.searchSource();
106106
builder.parseXContent(parser, false);
107107
builder.explain(searchTemplateRequest.isExplain());

modules/lang-painless/src/main/java/org/elasticsearch/painless/api/Json.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
package org.elasticsearch.painless.api;
1010

11-
import org.elasticsearch.xcontent.DeprecationHandler;
12-
import org.elasticsearch.xcontent.NamedXContentRegistry;
1311
import org.elasticsearch.xcontent.XContentBuilder;
1412
import org.elasticsearch.xcontent.XContentParser;
13+
import org.elasticsearch.xcontent.XContentParserConfiguration;
1514
import org.elasticsearch.xcontent.json.JsonXContent;
1615

1716
import java.io.IOException;
@@ -21,11 +20,7 @@ public class Json {
2120
* Load a string as the Java version of a JSON type, either List (JSON array), Map (JSON object), Number, Boolean or String
2221
*/
2322
public static Object load(String json) throws IOException {
24-
XContentParser parser = JsonXContent.jsonXContent.createParser(
25-
NamedXContentRegistry.EMPTY,
26-
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
27-
json
28-
);
23+
XContentParser parser = JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, json);
2924

3025
return switch (parser.nextToken()) {
3126
case START_ARRAY -> parser.list();

server/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.xcontent.NamedXContentRegistry;
2222
import org.elasticsearch.xcontent.XContentFactory;
2323
import org.elasticsearch.xcontent.XContentParser;
24+
import org.elasticsearch.xcontent.XContentParserConfiguration;
2425

2526
import java.io.IOException;
2627
import java.io.InputStream;
@@ -115,7 +116,11 @@ public static void validateAliasFilter(
115116
assert searchExecutionContext != null;
116117
try (
117118
XContentParser parser = XContentFactory.xContent(filter)
118-
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, filter)
119+
.createParser(
120+
XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry)
121+
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE),
122+
filter
123+
)
119124
) {
120125
validateAliasFilter(parser, searchExecutionContext);
121126
} catch (Exception e) {
@@ -140,7 +145,11 @@ public static void validateAliasFilter(
140145
InputStream inputStream = filter.streamInput();
141146
XContentParser parser = XContentFactory.xContentType(inputStream)
142147
.xContent()
143-
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, filter.streamInput())
148+
.createParser(
149+
XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry)
150+
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE),
151+
filter.streamInput()
152+
)
144153
) {
145154
validateAliasFilter(parser, searchExecutionContext);
146155
} catch (Exception e) {

server/src/main/java/org/elasticsearch/common/settings/Setting.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323
import org.elasticsearch.core.TimeValue;
2424
import org.elasticsearch.core.Tuple;
2525
import org.elasticsearch.index.mapper.DateFieldMapper;
26-
import org.elasticsearch.xcontent.DeprecationHandler;
27-
import org.elasticsearch.xcontent.NamedXContentRegistry;
2826
import org.elasticsearch.xcontent.ToXContentObject;
2927
import org.elasticsearch.xcontent.XContentBuilder;
3028
import org.elasticsearch.xcontent.XContentFactory;
3129
import org.elasticsearch.xcontent.XContentParser;
30+
import org.elasticsearch.xcontent.XContentParserConfiguration;
3231
import org.elasticsearch.xcontent.XContentType;
3332

3433
import java.io.IOException;
@@ -1740,10 +1739,7 @@ private static List<String> parseableStringToList(String parsableString) {
17401739
return List.of();
17411740
}
17421741
// fromXContent doesn't use named xcontent or deprecation.
1743-
try (
1744-
XContentParser xContentParser = XContentType.JSON.xContent()
1745-
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, parsableString)
1746-
) {
1742+
try (XContentParser xContentParser = XContentType.JSON.xContent().createParser(XContentParserConfiguration.EMPTY, parsableString)) {
17471743
xContentParser.nextToken();
17481744
return XContentParserUtils.parseList(xContentParser, p -> {
17491745
XContentParserUtils.ensureExpectedToken(XContentParser.Token.VALUE_STRING, p.currentToken(), p);

server/src/main/java/org/elasticsearch/common/settings/Settings.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@
2424
import org.elasticsearch.common.unit.MemorySizeValue;
2525
import org.elasticsearch.common.util.Maps;
2626
import org.elasticsearch.common.util.StringLiteralDeduplicator;
27-
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
2827
import org.elasticsearch.common.xcontent.XContentParserUtils;
2928
import org.elasticsearch.core.Booleans;
3029
import org.elasticsearch.core.Nullable;
3130
import org.elasticsearch.core.TimeValue;
3231
import org.elasticsearch.core.internal.io.IOUtils;
33-
import org.elasticsearch.xcontent.DeprecationHandler;
34-
import org.elasticsearch.xcontent.NamedXContentRegistry;
3532
import org.elasticsearch.xcontent.ToXContentFragment;
3633
import org.elasticsearch.xcontent.XContentBuilder;
3734
import org.elasticsearch.xcontent.XContentFactory;
3835
import org.elasticsearch.xcontent.XContentParser;
36+
import org.elasticsearch.xcontent.XContentParserConfiguration;
3937
import org.elasticsearch.xcontent.XContentType;
4038

4139
import java.io.IOException;
@@ -1139,10 +1137,7 @@ public Builder loadFromMap(Map<String, ?> map) {
11391137
* Loads settings from the actual string content that represents them using {@link #fromXContent(XContentParser)}
11401138
*/
11411139
public Builder loadFromSource(String source, XContentType xContentType) {
1142-
try (
1143-
XContentParser parser = XContentFactory.xContent(xContentType)
1144-
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)
1145-
) {
1140+
try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(XContentParserConfiguration.EMPTY, source)) {
11461141
this.put(fromXContent(parser, true, true));
11471142
} catch (Exception e) {
11481143
throw new SettingsException("Failed to load settings from [" + source + "]", e);
@@ -1172,10 +1167,7 @@ public Builder loadFromStream(String resourceName, InputStream is, boolean accep
11721167
throw new IllegalArgumentException("unable to detect content type from resource name [" + resourceName + "]");
11731168
}
11741169
// fromXContent doesn't use named xcontent or deprecation.
1175-
try (
1176-
XContentParser parser = XContentFactory.xContent(xContentType)
1177-
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, is)
1178-
) {
1170+
try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(XContentParserConfiguration.EMPTY, is)) {
11791171
if (parser.currentToken() == null) {
11801172
if (parser.nextToken() == null) {
11811173
return this; // empty file

server/src/main/java/org/elasticsearch/common/xcontent/XContentHelper.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,7 @@ public static Tuple<XContentType, Map<String, Object>> convertToMap(
196196
* error.
197197
*/
198198
public static Map<String, Object> convertToMap(XContent xContent, String string, boolean ordered) throws ElasticsearchParseException {
199-
// It is safe to use EMPTY here because this never uses namedObject
200-
try (
201-
XContentParser parser = xContent.createParser(
202-
NamedXContentRegistry.EMPTY,
203-
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
204-
string
205-
)
206-
) {
199+
try (XContentParser parser = xContent.createParser(XContentParserConfiguration.EMPTY, string)) {
207200
return ordered ? parser.mapOrdered() : parser.map();
208201
} catch (IOException e) {
209202
throw new ElasticsearchParseException("Failed to parse content to map", e);

server/src/main/java/org/elasticsearch/index/mapper/MapperService.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,7 @@ public static Map<String, Object> parseMapping(NamedXContentRegistry xContentReg
226226
// empty JSON is a common default value so it makes sense to optimize for it a little
227227
return Map.of();
228228
}
229-
try (
230-
XContentParser parser = XContentType.JSON.xContent()
231-
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, mappingSource)
232-
) {
229+
try (XContentParser parser = XContentType.JSON.xContent().createParser(parserConfig(xContentRegistry), mappingSource)) {
233230
return parser.map();
234231
}
235232
}
@@ -241,17 +238,16 @@ public static Map<String, Object> parseMapping(NamedXContentRegistry xContentReg
241238
throws IOException {
242239
try (
243240
InputStream in = CompressorFactory.COMPRESSOR.threadLocalInputStream(mappingSource.compressedReference().streamInput());
244-
XContentParser parser = XContentType.JSON.xContent()
245-
.createParser(
246-
XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry)
247-
.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE),
248-
in
249-
)
241+
XContentParser parser = XContentType.JSON.xContent().createParser(parserConfig(xContentRegistry), in)
250242
) {
251243
return parser.map();
252244
}
253245
}
254246

247+
private static XContentParserConfiguration parserConfig(NamedXContentRegistry xContentRegistry) {
248+
return XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry).withDeprecationHandler(LoggingDeprecationHandler.INSTANCE);
249+
}
250+
255251
/**
256252
* Update local mapping by applying the incoming mapping that have already been merged with the current one on the master
257253
*/

server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequestTests.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@
1414
import org.elasticsearch.common.io.stream.BytesStreamOutput;
1515
import org.elasticsearch.common.io.stream.StreamInput;
1616
import org.elasticsearch.common.io.stream.Writeable;
17-
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1817
import org.elasticsearch.index.RandomCreateIndexGenerator;
1918
import org.elasticsearch.test.AbstractWireSerializingTestCase;
20-
import org.elasticsearch.xcontent.NamedXContentRegistry;
2119
import org.elasticsearch.xcontent.XContentBuilder;
2220
import org.elasticsearch.xcontent.XContentFactory;
23-
import org.elasticsearch.xcontent.XContentParser;
2421
import org.elasticsearch.xcontent.XContentType;
2522
import org.elasticsearch.xcontent.json.JsonXContent;
2623

2724
import java.io.IOException;
28-
import java.util.Map;
2925
import java.util.Set;
3026

3127
import static org.hamcrest.CoreMatchers.equalTo;
@@ -161,29 +157,6 @@ public void testAlias() throws IOException {
161157
assertThat(e.getMessage(), containsString("Unknown token [START_ARRAY] in alias [filtered-data]"));
162158
}
163159

164-
public static void assertMappingsEqual(Map<String, String> expected, Map<String, String> actual) throws IOException {
165-
assertEquals(expected.keySet(), actual.keySet());
166-
167-
for (Map.Entry<String, String> expectedEntry : expected.entrySet()) {
168-
String expectedValue = expectedEntry.getValue();
169-
String actualValue = actual.get(expectedEntry.getKey());
170-
try (
171-
XContentParser expectedJson = JsonXContent.jsonXContent.createParser(
172-
NamedXContentRegistry.EMPTY,
173-
LoggingDeprecationHandler.INSTANCE,
174-
expectedValue
175-
);
176-
XContentParser actualJson = JsonXContent.jsonXContent.createParser(
177-
NamedXContentRegistry.EMPTY,
178-
LoggingDeprecationHandler.INSTANCE,
179-
actualValue
180-
)
181-
) {
182-
assertEquals(expectedJson.map(), actualJson.map());
183-
}
184-
}
185-
}
186-
187160
public static void assertAliasesEqual(Set<Alias> expected, Set<Alias> actual) throws IOException {
188161
assertEquals(expected, actual);
189162

0 commit comments

Comments
 (0)