File tree 2 files changed +22
-1
lines changed
main/java/org/elasticsearch/index/mapper/attachment
test/java/org/elasticsearch/plugin/mapper/attachments/test
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -295,6 +295,11 @@ public void parse(ParseContext context) throws IOException {
295
295
}
296
296
}
297
297
298
+ // Throw clean exception when no content is provided Fix #23
299
+ if (content == null ) {
300
+ throw new MapperParsingException ("No content is provided." );
301
+ }
302
+
298
303
Metadata metadata = new Metadata ();
299
304
if (contentType != null ) {
300
305
metadata .add (Metadata .CONTENT_TYPE , contentType );
Original file line number Diff line number Diff line change 25
25
import org .elasticsearch .common .logging .ESLogger ;
26
26
import org .elasticsearch .common .logging .Loggers ;
27
27
import org .elasticsearch .common .network .NetworkUtils ;
28
+ import org .elasticsearch .index .mapper .MapperParsingException ;
28
29
import org .elasticsearch .node .Node ;
29
30
import org .testng .annotations .*;
30
31
@@ -133,4 +134,19 @@ public void testSimpleAttachmentNoContentLengthLimit() throws Exception {
133
134
countResponse = node .client ().count (countRequest ("test" ).query (fieldQuery ("file" , "End" ))).actionGet ();
134
135
assertThat (countResponse .count (), equalTo (1l ));
135
136
}
136
- }
137
+
138
+ /**
139
+ * Test case for issue https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/23
140
+ * <br/>We throw a nicer exception when no content is provided
141
+ * @throws Exception
142
+ */
143
+ @ Test (expectedExceptions = MapperParsingException .class )
144
+ public void testNoContent () throws Exception {
145
+ String mapping = copyToStringFromClasspath ("/org/elasticsearch/index/mapper/xcontent/test-mapping.json" );
146
+
147
+ node .client ().admin ().indices ().putMapping (putMappingRequest ("test" ).type ("person" ).source (mapping )).actionGet ();
148
+
149
+ node .client ().index (indexRequest ("test" ).type ("person" )
150
+ .source (jsonBuilder ().startObject ().field ("file" ).startObject ().endObject ())).actionGet ();
151
+ }
152
+ }
You can’t perform that action at this time.
0 commit comments