Skip to content

Commit c6cdd3a

Browse files
committed
Revert "Report parser name and location in XContent deprecation warnings (#53752)"
This reverts commit 7636930. There is some randomization in the YAML test suite which means we can't check for exact xcontentlocation in the deprecation warning headers.
1 parent 8d5478f commit c6cdd3a

File tree

15 files changed

+58
-115
lines changed

15 files changed

+58
-115
lines changed

libs/x-content/src/main/java/org/elasticsearch/common/ParseField.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
package org.elasticsearch.common;
2020

2121
import org.elasticsearch.common.xcontent.DeprecationHandler;
22-
import org.elasticsearch.common.xcontent.XContentLocation;
2322

2423
import java.util.Collections;
2524
import java.util.HashSet;
2625
import java.util.Objects;
2726
import java.util.Set;
28-
import java.util.function.Supplier;
2927

3028
/**
3129
* Holds a field that can be found in a request while parsing and its different
@@ -117,22 +115,6 @@ public ParseField withAllDeprecated() {
117115
* names for this {@link ParseField}.
118116
*/
119117
public boolean match(String fieldName, DeprecationHandler deprecationHandler) {
120-
return match(null, () -> XContentLocation.UNKNOWN, fieldName, deprecationHandler);
121-
}
122-
123-
/**
124-
* Does {@code fieldName} match this field?
125-
* @param parserName
126-
* the name of the parent object holding this field
127-
* @param location
128-
* the XContentLocation of the field
129-
* @param fieldName
130-
* the field name to match against this {@link ParseField}
131-
* @param deprecationHandler called if {@code fieldName} is deprecated
132-
* @return true if <code>fieldName</code> matches any of the acceptable
133-
* names for this {@link ParseField}.
134-
*/
135-
public boolean match(String parserName, Supplier<XContentLocation> location, String fieldName, DeprecationHandler deprecationHandler) {
136118
Objects.requireNonNull(fieldName, "fieldName cannot be null");
137119
// if this parse field has not been completely deprecated then try to
138120
// match the preferred name
@@ -145,11 +127,11 @@ public boolean match(String parserName, Supplier<XContentLocation> location, Str
145127
for (String depName : deprecatedNames) {
146128
if (fieldName.equals(depName)) {
147129
if (fullyDeprecated) {
148-
deprecationHandler.usedDeprecatedField(parserName, location, fieldName);
130+
deprecationHandler.usedDeprecatedField(fieldName);
149131
} else if (allReplacedWith == null) {
150-
deprecationHandler.usedDeprecatedName(parserName, location, fieldName, name);
132+
deprecationHandler.usedDeprecatedName(fieldName, name);
151133
} else {
152-
deprecationHandler.usedDeprecatedField(parserName, location, fieldName, allReplacedWith);
134+
deprecationHandler.usedDeprecatedField(fieldName, allReplacedWith);
153135
}
154136
return true;
155137
}

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

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
package org.elasticsearch.common.xcontent;
2121

22-
import java.util.function.Supplier;
23-
2422
/**
2523
* Callback for notifying the creator of the {@link XContentParser} that
2624
* parsing hit a deprecated field.
@@ -34,35 +32,20 @@ public interface DeprecationHandler {
3432
*/
3533
DeprecationHandler THROW_UNSUPPORTED_OPERATION = new DeprecationHandler() {
3634
@Override
37-
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName, String replacedWith) {
38-
if (parserName != null) {
39-
throw new UnsupportedOperationException("deprecated fields not supported in [" + parserName + "] but got ["
40-
+ usedName + "] at [" + location.get() + "] which is a deprecated name for [" + replacedWith + "]");
41-
} else {
42-
throw new UnsupportedOperationException("deprecated fields not supported here but got ["
43-
+ usedName + "] which is a deprecated name for [" + replacedWith + "]");
44-
}
35+
public void usedDeprecatedField(String usedName, String replacedWith) {
36+
throw new UnsupportedOperationException("deprecated fields not supported here but got ["
37+
+ usedName + "] which is a deprecated name for [" + replacedWith + "]");
4538
}
4639
@Override
47-
public void usedDeprecatedName(String parserName, Supplier<XContentLocation> location, String usedName, String modernName) {
48-
if (parserName != null) {
49-
throw new UnsupportedOperationException("deprecated fields not supported in [" + parserName + "] but got ["
50-
+ usedName + "] at [" + location.get() + "] which has been replaced with [" + modernName + "]");
51-
} else {
52-
throw new UnsupportedOperationException("deprecated fields not supported here but got ["
53-
+ usedName + "] which has been replaced with [" + modernName + "]");
54-
}
40+
public void usedDeprecatedName(String usedName, String modernName) {
41+
throw new UnsupportedOperationException("deprecated fields not supported here but got ["
42+
+ usedName + "] which has been replaced with [" + modernName + "]");
5543
}
5644

5745
@Override
58-
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName) {
59-
if (parserName != null) {
60-
throw new UnsupportedOperationException("deprecated fields not supported in [" + parserName + "] but got ["
61-
+ usedName + "] at [" + location.get() + "] which has been deprecated entirely");
62-
} else {
63-
throw new UnsupportedOperationException("deprecated fields not supported here but got ["
64-
+ usedName + "] which has been deprecated entirely");
65-
}
46+
public void usedDeprecatedField(String usedName) {
47+
throw new UnsupportedOperationException("deprecated fields not supported here but got ["
48+
+ usedName + "] which has been deprecated entirely");
6649
}
6750
};
6851

@@ -71,17 +54,17 @@ public void usedDeprecatedField(String parserName, Supplier<XContentLocation> lo
7154
*/
7255
DeprecationHandler IGNORE_DEPRECATIONS = new DeprecationHandler() {
7356
@Override
74-
public void usedDeprecatedName(String parserName, Supplier<XContentLocation> location, String usedName, String modernName) {
57+
public void usedDeprecatedName(String usedName, String modernName) {
7558

7659
}
7760

7861
@Override
79-
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName, String replacedWith) {
62+
public void usedDeprecatedField(String usedName, String replacedWith) {
8063

8164
}
8265

8366
@Override
84-
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName) {
67+
public void usedDeprecatedField(String usedName) {
8568

8669
}
8770
};
@@ -91,21 +74,20 @@ public void usedDeprecatedField(String parserName, Supplier<XContentLocation> lo
9174
* @param usedName the provided field name
9275
* @param modernName the modern name for the field
9376
*/
94-
void usedDeprecatedName(String parserName, Supplier<XContentLocation> location, String usedName, String modernName);
77+
void usedDeprecatedName(String usedName, String modernName);
9578

9679
/**
9780
* Called when the provided field name matches the current field but the entire
9881
* field has been marked as deprecated and another field should be used
9982
* @param usedName the provided field name
10083
* @param replacedWith the name of the field that replaced this field
10184
*/
102-
void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName, String replacedWith);
85+
void usedDeprecatedField(String usedName, String replacedWith);
10386

10487
/**
10588
* Called when the provided field name matches the current field but the entire
10689
* field has been marked as deprecated with no replacement
10790
* @param usedName the provided field name
10891
*/
109-
void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName);
110-
92+
void usedDeprecatedField(String usedName);
11193
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ private class FieldParser {
571571
}
572572

573573
void assertSupports(String parserName, XContentParser parser, String currentFieldName) {
574-
if (parseField.match(parserName, parser::getTokenLocation, currentFieldName, parser.getDeprecationHandler()) == false) {
574+
if (parseField.match(currentFieldName, parser.getDeprecationHandler()) == false) {
575575
throw new XContentParseException(parser.getTokenLocation(),
576576
"[" + parserName + "] parsefield doesn't accept: " + currentFieldName);
577577
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
* position of a parsing error to end users and consequently have line and
2626
* column numbers starting from 1.
2727
*/
28-
public final class XContentLocation {
29-
30-
public static final XContentLocation UNKNOWN = new XContentLocation(-1, -1);
31-
28+
public class XContentLocation {
3229
public final int lineNumber;
3330
public final int columnNumber;
3431

libs/x-content/src/test/java/org/elasticsearch/common/ParseFieldTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public void testDeprecatedWithNoReplacement() {
6666
ParseField field = new ParseField(name).withDeprecation(alternatives).withAllDeprecated();
6767
assertFalse(field.match("not a field name", LoggingDeprecationHandler.INSTANCE));
6868
assertTrue(field.match("dep", LoggingDeprecationHandler.INSTANCE));
69-
assertWarnings("Deprecated field [dep] used, this field is unused and will be removed entirely");
69+
assertWarnings("Deprecated field [dep] used, which has been removed entirely");
7070
assertTrue(field.match("old_dep", LoggingDeprecationHandler.INSTANCE));
71-
assertWarnings("Deprecated field [old_dep] used, this field is unused and will be removed entirely");
71+
assertWarnings("Deprecated field [old_dep] used, which has been removed entirely");
7272
assertTrue(field.match("new_dep", LoggingDeprecationHandler.INSTANCE));
73-
assertWarnings("Deprecated field [new_dep] used, this field is unused and will be removed entirely");
73+
assertWarnings("Deprecated field [new_dep] used, which has been removed entirely");
7474

7575

7676
}

libs/x-content/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class TestStruct {
223223
objectParser.declareField((i, v, c) -> v.test = i.text(), new ParseField("test", "old_test"), ObjectParser.ValueType.STRING);
224224
objectParser.parse(parser, s, null);
225225
assertEquals("foo", s.test);
226-
assertWarnings("[foo][1:15] Deprecated field [old_test] used, expected [test] instead");
226+
assertWarnings("Deprecated field [old_test] used, expected [test] instead");
227227
}
228228

229229
public void testFailOnValueType() throws IOException {

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ScriptProcessorFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void testInlineBackcompat() throws Exception {
9898
configMap.put("inline", "code");
9999

100100
factory.create(null, randomAlphaOfLength(10), configMap);
101-
assertWarnings("[script][1:11] Deprecated field [inline] used, expected [source] instead");
101+
assertWarnings("Deprecated field [inline] used, expected [source] instead");
102102
}
103103

104104
public void testFactoryInvalidateWithInvalidCompiledScript() throws Exception {

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import org.elasticsearch.common.ParseField;
2424
import org.elasticsearch.common.logging.DeprecationLogger;
2525

26-
import java.util.function.Supplier;
27-
2826
/**
2927
* Logs deprecations to the {@link DeprecationLogger}.
3028
* <p>
@@ -51,23 +49,17 @@ private LoggingDeprecationHandler() {
5149
}
5250

5351
@Override
54-
public void usedDeprecatedName(String parserName, Supplier<XContentLocation> location, String usedName, String modernName) {
55-
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
56-
deprecationLogger.deprecated("{}Deprecated field [{}] used, expected [{}] instead",
57-
prefix, usedName, modernName);
52+
public void usedDeprecatedName(String usedName, String modernName) {
53+
deprecationLogger.deprecated("Deprecated field [{}] used, expected [{}] instead", usedName, modernName);
5854
}
5955

6056
@Override
61-
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName, String replacedWith) {
62-
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
63-
deprecationLogger.deprecated("{}Deprecated field [{}] used, replaced by [{}]",
64-
prefix, usedName, replacedWith);
57+
public void usedDeprecatedField(String usedName, String replacedWith) {
58+
deprecationLogger.deprecated("Deprecated field [{}] used, replaced by [{}]", usedName, replacedWith);
6559
}
6660

6761
@Override
68-
public void usedDeprecatedField(String parserName, Supplier<XContentLocation> location, String usedName) {
69-
String prefix = parserName == null ? "" : "[" + parserName + "][" + location.get() + "] ";
70-
deprecationLogger.deprecated("{}Deprecated field [{}] used, this field is unused and will be removed entirely",
71-
prefix, usedName);
62+
public void usedDeprecatedField(String usedName) {
63+
deprecationLogger.deprecated("Deprecated field [{}] used, which has been removed entirely", usedName);
7264
}
7365
}

server/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public void testDeprecation() throws IOException {
302302
QueryBuilder q = parseQuery(query);
303303
QueryBuilder expected = new BoolQueryBuilder().mustNot(new MatchAllQueryBuilder());
304304
assertEquals(expected, q);
305-
assertWarnings("[bool][1:24] Deprecated field [mustNot] used, expected [must_not] instead");
305+
assertWarnings("Deprecated field [mustNot] used, expected [must_not] instead");
306306
}
307307

308308
public void testRewrite() throws IOException {

server/src/test/java/org/elasticsearch/script/StoredScriptTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void testSourceParsing() throws Exception {
104104

105105
assertThat(parsed, equalTo(source));
106106
}
107-
assertWarnings("[stored script source][1:33] Deprecated field [code] used, expected [source] instead");
107+
assertWarnings("Deprecated field [code] used, expected [source] instead");
108108

109109
// complex script with script object and empty options
110110
try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) {

0 commit comments

Comments
 (0)