Remove lenient boolean handling
With this commit we remove some leftovers from #26389 which cleaned up lenient boolean handling. Relates #26389 Relates #22298 Relates #34467
This commit is contained in:
parent
f5ef2482df
commit
92b2e1a209
|
@ -204,26 +204,6 @@ public interface XContentParser extends Closeable {
|
|||
|
||||
boolean booleanValue() throws IOException;
|
||||
|
||||
// TODO #22298: Remove this method and replace all call sites with #isBooleanValue()
|
||||
/**
|
||||
* returns true if the current value is boolean in nature.
|
||||
* values that are considered booleans:
|
||||
* - boolean value (true/false)
|
||||
* - numeric integers (=0 is considered as false, !=0 is true)
|
||||
* - one of the following strings: "true","false","on","off","yes","no","1","0"
|
||||
*
|
||||
* @deprecated Just present for providing backwards compatibility. Use {@link #isBooleanValue()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean isBooleanValueLenient() throws IOException;
|
||||
|
||||
// TODO #22298: Remove this method and replace all call sites with #booleanValue()
|
||||
/**
|
||||
* @deprecated Just present for providing backwards compatibility. Use {@link #booleanValue()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean booleanValueLenient() throws IOException;
|
||||
|
||||
/**
|
||||
* Reads a plain binary value that was written via one of the following methods:
|
||||
*
|
||||
|
|
|
@ -98,34 +98,6 @@ public abstract class AbstractXContentParser implements XContentParser {
|
|||
return doBooleanValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isBooleanValueLenient() throws IOException {
|
||||
switch (currentToken()) {
|
||||
case VALUE_BOOLEAN:
|
||||
return true;
|
||||
case VALUE_NUMBER:
|
||||
NumberType numberType = numberType();
|
||||
return numberType == NumberType.LONG || numberType == NumberType.INT;
|
||||
case VALUE_STRING:
|
||||
return Booleans.isBooleanLenient(textCharacters(), textOffset(), textLength());
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean booleanValueLenient() throws IOException {
|
||||
Token token = currentToken();
|
||||
if (token == Token.VALUE_NUMBER) {
|
||||
return intValue() != 0;
|
||||
} else if (token == Token.VALUE_STRING) {
|
||||
return Booleans.parseBooleanLenient(textCharacters(), textOffset(), textLength(), false /* irrelevant */);
|
||||
}
|
||||
return doBooleanValue();
|
||||
}
|
||||
|
||||
protected abstract boolean doBooleanValue() throws IOException;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -189,35 +189,6 @@ public class XContentParserTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // #isBooleanValueLenient() and #booleanValueLenient() are the test subjects
|
||||
public void testReadLenientBooleans() throws IOException {
|
||||
// allow String, boolean and int representations of lenient booleans
|
||||
String falsy = randomFrom("\"off\"", "\"no\"", "\"0\"", "0", "\"false\"", "false");
|
||||
String truthy = randomFrom("\"on\"", "\"yes\"", "\"1\"", "1", "\"true\"", "true");
|
||||
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"foo\": " + falsy + ", \"bar\": " + truthy + "}")) {
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
assertThat(token, equalTo(XContentParser.Token.START_OBJECT));
|
||||
token = parser.nextToken();
|
||||
assertThat(token, equalTo(XContentParser.Token.FIELD_NAME));
|
||||
assertThat(parser.currentName(), equalTo("foo"));
|
||||
token = parser.nextToken();
|
||||
assertThat(token, isIn(
|
||||
Arrays.asList(XContentParser.Token.VALUE_STRING, XContentParser.Token.VALUE_NUMBER, XContentParser.Token.VALUE_BOOLEAN)));
|
||||
assertTrue(parser.isBooleanValueLenient());
|
||||
assertFalse(parser.booleanValueLenient());
|
||||
|
||||
token = parser.nextToken();
|
||||
assertThat(token, equalTo(XContentParser.Token.FIELD_NAME));
|
||||
assertThat(parser.currentName(), equalTo("bar"));
|
||||
token = parser.nextToken();
|
||||
assertThat(token, isIn(
|
||||
Arrays.asList(XContentParser.Token.VALUE_STRING, XContentParser.Token.VALUE_NUMBER, XContentParser.Token.VALUE_BOOLEAN)));
|
||||
assertTrue(parser.isBooleanValueLenient());
|
||||
assertTrue(parser.booleanValueLenient());
|
||||
}
|
||||
}
|
||||
|
||||
public void testReadBooleansFailsForLenientBooleans() throws IOException {
|
||||
String falsy = randomFrom("\"off\"", "\"no\"", "\"0\"", "0");
|
||||
String truthy = randomFrom("\"on\"", "\"yes\"", "\"1\"", "1");
|
||||
|
|
|
@ -427,8 +427,7 @@ public class MultiGetRequest extends ActionRequest
|
|||
} else if (VERSION_TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
|
||||
versionType = VersionType.fromString(parser.text());
|
||||
} else if (SOURCE.match(currentFieldName, parser.getDeprecationHandler())) {
|
||||
// check lenient to avoid interpreting the value as string but parse strict in order to provoke an error early on.
|
||||
if (parser.isBooleanValueLenient()) {
|
||||
if (parser.isBooleanValue()) {
|
||||
fetchSourceContext = new FetchSourceContext(parser.booleanValue(), fetchSourceContext.includes(),
|
||||
fetchSourceContext.excludes());
|
||||
} else if (token == Token.VALUE_STRING) {
|
||||
|
|
|
@ -98,24 +98,6 @@ public class MultiGetRequestTests extends ESTestCase {
|
|||
"unexpected token [START_OBJECT], expected [FIELD_NAME] or [START_ARRAY]"));
|
||||
}
|
||||
|
||||
public void testAddWithInvalidSourceValueIsRejected() throws Exception {
|
||||
String sourceValue = randomFrom("on", "off", "0", "1");
|
||||
XContentParser parser = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("docs")
|
||||
.startObject()
|
||||
.field("_source", sourceValue)
|
||||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
);
|
||||
|
||||
MultiGetRequest multiGetRequest = new MultiGetRequest();
|
||||
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> multiGetRequest.add
|
||||
(randomAlphaOfLength(5), randomAlphaOfLength(3), null, FetchSourceContext.FETCH_SOURCE, null, parser, true));
|
||||
assertEquals("Failed to parse value [" + sourceValue + "] as only [true] or [false] are allowed.", ex.getMessage());
|
||||
}
|
||||
|
||||
public void testAddWithValidSourceValueIsAccepted() throws Exception {
|
||||
XContentParser parser = createParser(XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
|
|
|
@ -253,18 +253,6 @@ public class WatcherXContentParser implements XContentParser {
|
|||
return parser.booleanValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecated")
|
||||
public boolean isBooleanValueLenient() throws IOException {
|
||||
return parser.isBooleanValueLenient();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecated")
|
||||
public boolean booleanValueLenient() throws IOException {
|
||||
return parser.booleanValueLenient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] binaryValue() throws IOException {
|
||||
return parser.binaryValue();
|
||||
|
|
Loading…
Reference in New Issue