diff --git a/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java b/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java index 4935b83c45bd2..81cc39c5793cf 100644 --- a/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java +++ b/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java @@ -204,26 +204,6 @@ enum NumberType { 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: * diff --git a/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java b/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java index 69d6736cea761..51bb5c3c65f6d 100644 --- a/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java +++ b/libs/x-content/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java @@ -98,34 +98,6 @@ public boolean booleanValue() throws IOException { 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 diff --git a/libs/x-content/src/test/java/org/elasticsearch/common/xcontent/XContentParserTests.java b/libs/x-content/src/test/java/org/elasticsearch/common/xcontent/XContentParserTests.java index 6fb4f207de0e9..113c21bacd10e 100644 --- a/libs/x-content/src/test/java/org/elasticsearch/common/xcontent/XContentParserTests.java +++ b/libs/x-content/src/test/java/org/elasticsearch/common/xcontent/XContentParserTests.java @@ -189,35 +189,6 @@ private Map readMapStrings(String source) throws IOException { } } - @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"); diff --git a/server/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java b/server/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java index 0ea564154ab0b..875015f8a9879 100644 --- a/server/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java +++ b/server/src/main/java/org/elasticsearch/action/get/MultiGetRequest.java @@ -427,8 +427,7 @@ private static void parseDocuments(XContentParser parser, List items, @Nul } 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) { diff --git a/server/src/test/java/org/elasticsearch/action/get/MultiGetRequestTests.java b/server/src/test/java/org/elasticsearch/action/get/MultiGetRequestTests.java index fcb4539c9afe7..fd2a1e5dca8e4 100644 --- a/server/src/test/java/org/elasticsearch/action/get/MultiGetRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/get/MultiGetRequestTests.java @@ -98,24 +98,6 @@ public void testUnexpectedField() throws IOException { "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() diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/WatcherXContentParser.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/WatcherXContentParser.java index c841d6c11ecf3..be422d4c38da7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/WatcherXContentParser.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/support/xcontent/WatcherXContentParser.java @@ -253,18 +253,6 @@ public boolean booleanValue() throws IOException { 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();