@@ -159,7 +159,14 @@ public void testStore() throws Exception {
159159 assertEquals (1457654400000L , storedField .numericValue ().longValue ());
160160 }
161161
162- public void testIgnoreMalformed () throws Exception {
162+ public void testIgnoreMalformed () throws IOException {
163+ testIgnoreMalfomedForValue ("2016-03-99" ,
164+ "failed to parse date field [2016-03-99] with format [strict_date_optional_time||epoch_millis]" );
165+ testIgnoreMalfomedForValue ("-2147483648" ,
166+ "Invalid value for Year (valid values -999999999 - 999999999): -2147483648" );
167+ }
168+
169+ private void testIgnoreMalfomedForValue (String value , String expectedException ) throws IOException {
163170 String mapping = Strings .toString (XContentFactory .jsonBuilder ().startObject ().startObject ("type" )
164171 .startObject ("properties" ).startObject ("field" ).field ("type" , "date" ).endObject ().endObject ()
165172 .endObject ().endObject ());
@@ -171,12 +178,11 @@ public void testIgnoreMalformed() throws Exception {
171178 ThrowingRunnable runnable = () -> mapper .parse (new SourceToParse ("test" , "type" , "1" , BytesReference
172179 .bytes (XContentFactory .jsonBuilder ()
173180 .startObject ()
174- .field ("field" , "2016-03-99" )
181+ .field ("field" , value )
175182 .endObject ()),
176183 XContentType .JSON ));
177184 MapperParsingException e = expectThrows (MapperParsingException .class , runnable );
178- assertThat (e .getCause ().getMessage (),
179- containsString ("failed to parse date field [2016-03-99] with format [strict_date_optional_time||epoch_millis]" ));
185+ assertThat (e .getCause ().getMessage (), containsString (expectedException ));
180186
181187 mapping = Strings .toString (XContentFactory .jsonBuilder ().startObject ().startObject ("type" )
182188 .startObject ("properties" ).startObject ("field" ).field ("type" , "date" )
@@ -188,7 +194,7 @@ public void testIgnoreMalformed() throws Exception {
188194 ParsedDocument doc = mapper2 .parse (new SourceToParse ("test" , "type" , "1" , BytesReference
189195 .bytes (XContentFactory .jsonBuilder ()
190196 .startObject ()
191- .field ("field" , ":1" )
197+ .field ("field" , value )
192198 .endObject ()),
193199 XContentType .JSON ));
194200
0 commit comments