Skip to content

Commit aa59355

Browse files
committed
Catch InputCoercionException thrown by Jackson parser (elastic#57287) (elastic#57330)
Jackson 2.10 library has added a new type of error that is thrown when a numeric value is out of range. This error should be catch and handle properly in case the flag ignore_malformed has been set to true.
1 parent 2405676 commit aa59355

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

server/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.fasterxml.jackson.core.JsonParseException;
2323

24+
import com.fasterxml.jackson.core.exc.InputCoercionException;
2425
import org.apache.lucene.document.DoublePoint;
2526
import org.apache.lucene.document.Field;
2627
import org.apache.lucene.document.FloatPoint;
@@ -1048,7 +1049,7 @@ protected void parseCreateField(ParseContext context, List<IndexableField> field
10481049
} else {
10491050
try {
10501051
numericValue = fieldType().type.parse(parser, coerce.value());
1051-
} catch (IllegalArgumentException | JsonParseException e) {
1052+
} catch (InputCoercionException | IllegalArgumentException | JsonParseException e) {
10521053
if (ignoreMalformed.value() && parser.currentToken().isValue()) {
10531054
context.addIgnoredField(fieldType.name());
10541055
return;

server/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java

+20
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import com.carrotsearch.randomizedtesting.annotations.Timeout;
2323
import org.apache.lucene.index.DocValuesType;
2424
import org.apache.lucene.index.IndexableField;
25+
import org.elasticsearch.action.index.IndexRequest;
26+
import org.elasticsearch.action.index.IndexResponse;
2527
import org.elasticsearch.common.Strings;
2628
import org.elasticsearch.common.bytes.BytesReference;
2729
import org.elasticsearch.common.compress.CompressedXContent;
@@ -32,6 +34,7 @@
3234
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
3335
import org.elasticsearch.index.mapper.NumberFieldTypeTests.OutOfRangeSpec;
3436
import org.elasticsearch.index.termvectors.TermVectorsService;
37+
import org.elasticsearch.rest.RestStatus;
3538

3639
import java.io.ByteArrayInputStream;
3740
import java.io.IOException;
@@ -453,6 +456,23 @@ public void testOutOfRangeValues() throws IOException {
453456
parseRequest(NumberType.LONG, createIndexRequest("-9223372036854775808.9"));
454457
}
455458

459+
public void testLongIndexingOutOfRange() throws Exception {
460+
String mapping = Strings.toString(XContentFactory.jsonBuilder()
461+
.startObject().startObject("_doc")
462+
.startObject("properties")
463+
.startObject("number")
464+
.field("type", "long")
465+
.field("ignore_malformed", true)
466+
.endObject().endObject()
467+
.endObject().endObject());
468+
createIndex("test57287");
469+
client().admin().indices().preparePutMapping("test57287")
470+
.setType("_doc").setSource(mapping, XContentType.JSON).get();
471+
String doc = "{\"number\" : 9223372036854775808}";
472+
IndexResponse response = client().index(new IndexRequest("test57287").source(doc, XContentType.JSON)).get();
473+
assertTrue(response.status() == RestStatus.CREATED);
474+
}
475+
456476
private void parseRequest(NumberType type, BytesReference content) throws IOException {
457477
createDocumentMapper(type).parse(new SourceToParse("test", "type", "1", content, XContentType.JSON));
458478
}

0 commit comments

Comments
 (0)