Skip to content

Commit

Permalink
Do not throw exception when flat_object field is explicitly null
Browse files Browse the repository at this point in the history
It is valid for a flat_object field to have an explicit value of
null. (It's functionally the same as not specifying the field at
all.) Prior to this fix, though, we would erroneously advance the
context parser to the next token, violating the contract with
DocumentParser (which says that a call to parseCreateField with
a null value should complete with the parser still pointing at
the null value -- it is DocumentParser's responsibility to advance).

Signed-off-by: Michael Froh <[email protected]>
  • Loading branch information
msfroh committed Aug 23, 2024
1 parent ed65482 commit b416205
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ setup:
} ]
}
}

- do:
index:
index: test_partial_flat_object
id: 4
body: {
"issue": {
"number": 999,
"labels": null
}
}
- do:
indices.refresh:
index: test_partial_flat_object
Expand Down Expand Up @@ -135,7 +144,7 @@ teardown:
}
}

- length: { hits.hits: 3 }
- length: { hits.hits: 4 }

# Match Query with exact dot path.
- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,7 @@ protected void parseCreateField(ParseContext context) throws IOException {
if (context.externalValueSet()) {
String value = context.externalValue().toString();
parseValueAddFields(context, value, fieldType().name());
} else if (context.parser().currentToken() == XContentParser.Token.VALUE_NULL) {
context.parser().nextToken(); // This triggers an exception in DocumentParser.
// We could remove the above nextToken() call to skip the null value, but the existing
// behavior (since 2.7) throws the exception.
} else {
} else if (context.parser().currentToken() != XContentParser.Token.VALUE_NULL) {
JsonToStringXContentParser jsonToStringParser = new JsonToStringXContentParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.IGNORE_DEPRECATIONS,
Expand Down

0 comments on commit b416205

Please sign in to comment.