@@ -159,7 +159,14 @@ public void testStore() throws Exception {
159
159
assertEquals (1457654400000L , storedField .numericValue ().longValue ());
160
160
}
161
161
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 {
163
170
String mapping = Strings .toString (XContentFactory .jsonBuilder ().startObject ().startObject ("type" )
164
171
.startObject ("properties" ).startObject ("field" ).field ("type" , "date" ).endObject ().endObject ()
165
172
.endObject ().endObject ());
@@ -171,12 +178,11 @@ public void testIgnoreMalformed() throws Exception {
171
178
ThrowingRunnable runnable = () -> mapper .parse (new SourceToParse ("test" , "1" , BytesReference
172
179
.bytes (XContentFactory .jsonBuilder ()
173
180
.startObject ()
174
- .field ("field" , "2016-03-99" )
181
+ .field ("field" , value )
175
182
.endObject ()),
176
183
XContentType .JSON ));
177
184
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 ));
180
186
181
187
mapping = Strings .toString (XContentFactory .jsonBuilder ().startObject ().startObject ("type" )
182
188
.startObject ("properties" ).startObject ("field" ).field ("type" , "date" )
@@ -188,7 +194,7 @@ public void testIgnoreMalformed() throws Exception {
188
194
ParsedDocument doc = mapper2 .parse (new SourceToParse ("test" , "1" , BytesReference
189
195
.bytes (XContentFactory .jsonBuilder ()
190
196
.startObject ()
191
- .field ("field" , ":1" )
197
+ .field ("field" , value )
192
198
.endObject ()),
193
199
XContentType .JSON ));
194
200
0 commit comments