Skip to content

Commit 14c5007

Browse files
Remove lenient boolean handling
With this commit we remove some leftovers from elastic#26389 which cleaned up lenient boolean handling. Relates elastic#26389 Relates elastic#22298
1 parent 9bb620e commit 14c5007

File tree

6 files changed

+1
-109
lines changed

6 files changed

+1
-109
lines changed

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -204,26 +204,6 @@ enum NumberType {
204204

205205
boolean booleanValue() throws IOException;
206206

207-
// TODO #22298: Remove this method and replace all call sites with #isBooleanValue()
208-
/**
209-
* returns true if the current value is boolean in nature.
210-
* values that are considered booleans:
211-
* - boolean value (true/false)
212-
* - numeric integers (=0 is considered as false, !=0 is true)
213-
* - one of the following strings: "true","false","on","off","yes","no","1","0"
214-
*
215-
* @deprecated Just present for providing backwards compatibility. Use {@link #isBooleanValue()} instead.
216-
*/
217-
@Deprecated
218-
boolean isBooleanValueLenient() throws IOException;
219-
220-
// TODO #22298: Remove this method and replace all call sites with #booleanValue()
221-
/**
222-
* @deprecated Just present for providing backwards compatibility. Use {@link #booleanValue()} instead.
223-
*/
224-
@Deprecated
225-
boolean booleanValueLenient() throws IOException;
226-
227207
/**
228208
* Reads a plain binary value that was written via one of the following methods:
229209
*

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -98,34 +98,6 @@ public boolean booleanValue() throws IOException {
9898
return doBooleanValue();
9999
}
100100

101-
@Override
102-
@Deprecated
103-
public boolean isBooleanValueLenient() throws IOException {
104-
switch (currentToken()) {
105-
case VALUE_BOOLEAN:
106-
return true;
107-
case VALUE_NUMBER:
108-
NumberType numberType = numberType();
109-
return numberType == NumberType.LONG || numberType == NumberType.INT;
110-
case VALUE_STRING:
111-
return Booleans.isBooleanLenient(textCharacters(), textOffset(), textLength());
112-
default:
113-
return false;
114-
}
115-
}
116-
117-
@Override
118-
@Deprecated
119-
public boolean booleanValueLenient() throws IOException {
120-
Token token = currentToken();
121-
if (token == Token.VALUE_NUMBER) {
122-
return intValue() != 0;
123-
} else if (token == Token.VALUE_STRING) {
124-
return Booleans.parseBooleanLenient(textCharacters(), textOffset(), textLength(), false /* irrelevant */);
125-
}
126-
return doBooleanValue();
127-
}
128-
129101
protected abstract boolean doBooleanValue() throws IOException;
130102

131103
@Override

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -189,35 +189,6 @@ private Map<String, String> readMapStrings(String source) throws IOException {
189189
}
190190
}
191191

192-
@SuppressWarnings("deprecation") // #isBooleanValueLenient() and #booleanValueLenient() are the test subjects
193-
public void testReadLenientBooleans() throws IOException {
194-
// allow String, boolean and int representations of lenient booleans
195-
String falsy = randomFrom("\"off\"", "\"no\"", "\"0\"", "0", "\"false\"", "false");
196-
String truthy = randomFrom("\"on\"", "\"yes\"", "\"1\"", "1", "\"true\"", "true");
197-
198-
try (XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"foo\": " + falsy + ", \"bar\": " + truthy + "}")) {
199-
XContentParser.Token token = parser.nextToken();
200-
assertThat(token, equalTo(XContentParser.Token.START_OBJECT));
201-
token = parser.nextToken();
202-
assertThat(token, equalTo(XContentParser.Token.FIELD_NAME));
203-
assertThat(parser.currentName(), equalTo("foo"));
204-
token = parser.nextToken();
205-
assertThat(token, isIn(
206-
Arrays.asList(XContentParser.Token.VALUE_STRING, XContentParser.Token.VALUE_NUMBER, XContentParser.Token.VALUE_BOOLEAN)));
207-
assertTrue(parser.isBooleanValueLenient());
208-
assertFalse(parser.booleanValueLenient());
209-
210-
token = parser.nextToken();
211-
assertThat(token, equalTo(XContentParser.Token.FIELD_NAME));
212-
assertThat(parser.currentName(), equalTo("bar"));
213-
token = parser.nextToken();
214-
assertThat(token, isIn(
215-
Arrays.asList(XContentParser.Token.VALUE_STRING, XContentParser.Token.VALUE_NUMBER, XContentParser.Token.VALUE_BOOLEAN)));
216-
assertTrue(parser.isBooleanValueLenient());
217-
assertTrue(parser.booleanValueLenient());
218-
}
219-
}
220-
221192
public void testReadBooleansFailsForLenientBooleans() throws IOException {
222193
String falsy = randomFrom("\"off\"", "\"no\"", "\"0\"", "0");
223194
String truthy = randomFrom("\"on\"", "\"yes\"", "\"1\"", "1");

server/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ private static void parseDocuments(XContentParser parser, List<Item> items, @Nul
427427
} else if (VERSION_TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
428428
versionType = VersionType.fromString(parser.text());
429429
} else if (SOURCE.match(currentFieldName, parser.getDeprecationHandler())) {
430-
// check lenient to avoid interpreting the value as string but parse strict in order to provoke an error early on.
431-
if (parser.isBooleanValueLenient()) {
430+
if (parser.isBooleanValue()) {
432431
fetchSourceContext = new FetchSourceContext(parser.booleanValue(), fetchSourceContext.includes(),
433432
fetchSourceContext.excludes());
434433
} else if (token == Token.VALUE_STRING) {

server/src/test/java/org/elasticsearch/action/get/MultiGetRequestTests.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,6 @@ public void testUnexpectedField() throws IOException {
9898
"unexpected token [START_OBJECT], expected [FIELD_NAME] or [START_ARRAY]"));
9999
}
100100

101-
public void testAddWithInvalidSourceValueIsRejected() throws Exception {
102-
String sourceValue = randomFrom("on", "off", "0", "1");
103-
XContentParser parser = createParser(XContentFactory.jsonBuilder()
104-
.startObject()
105-
.startArray("docs")
106-
.startObject()
107-
.field("_source", sourceValue)
108-
.endObject()
109-
.endArray()
110-
.endObject()
111-
);
112-
113-
MultiGetRequest multiGetRequest = new MultiGetRequest();
114-
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> multiGetRequest.add
115-
(randomAlphaOfLength(5), randomAlphaOfLength(3), null, FetchSourceContext.FETCH_SOURCE, null, parser, true));
116-
assertEquals("Failed to parse value [" + sourceValue + "] as only [true] or [false] are allowed.", ex.getMessage());
117-
}
118-
119101
public void testAddWithValidSourceValueIsAccepted() throws Exception {
120102
XContentParser parser = createParser(XContentFactory.jsonBuilder()
121103
.startObject()

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/WatcherXContentParser.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,6 @@ public boolean booleanValue() throws IOException {
253253
return parser.booleanValue();
254254
}
255255

256-
@Override
257-
@SuppressWarnings("deprecated")
258-
public boolean isBooleanValueLenient() throws IOException {
259-
return parser.isBooleanValueLenient();
260-
}
261-
262-
@Override
263-
@SuppressWarnings("deprecated")
264-
public boolean booleanValueLenient() throws IOException {
265-
return parser.booleanValueLenient();
266-
}
267-
268256
@Override
269257
public byte[] binaryValue() throws IOException {
270258
return parser.binaryValue();

0 commit comments

Comments
 (0)