NPE if "content" is missing in mapper-attachment plugin
Curl recreation: curl -X DELETE "localhost:9200/test" curl -X PUT "localhost:9200/test" -d '{ "settings" : { "index" : { "number_of_shards" : 1, "number_of_replicas" : 0 }} }' curl -X GET "localhost:9200/_cluster/health?wait_for_status=green&pretty=1&timeout=5s" curl -X PUT "localhost:9200/test/attachment/_mapping" -d '{ "attachment" : { "properties" : { "file" : { "type" : "attachment" } } } }' curl -X PUT "localhost:9200/test/attachment/1" -d '{ "file" : { "_content_type" : "application/pdf", "_name" : "resource/name/of/my.pdf" } } ' Produces a: {"error":"NullPointerException[null]","status":500} And in ES logs: [2013-02-20 12:49:04,445][DEBUG][action.index ] [Drake, Frank] [test][0], node[LI6crwNKQmu1ue1u7mlqGA], [P], s[STARTED]: Failed to execute [index {[test][attachment][1], source[{ "file" : { "_content_type" : "application/pdf", "_name" : "resource/name/of/my.pdf" } } ]}] java.lang.NullPointerException at org.elasticsearch.common.io.FastByteArrayInputStream.<init>(FastByteArrayInputStream.java:90) at org.elasticsearch.index.mapper.attachment.AttachmentMapper.parse(AttachmentMapper.java:309) at org.elasticsearch.index.mapper.object.ObjectMapper.serializeObject(ObjectMapper.java:507) at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:449) at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:486) at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:430) at org.elasticsearch.index.shard.service.InternalIndexShard.prepareIndex(InternalIndexShard.java:318) at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:203) at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:531) at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:429) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:680) Closes #23
This commit is contained in:
parent
69f8bdea03
commit
eba4da7086
|
@ -295,6 +295,11 @@ public class AttachmentMapper implements Mapper {
|
|||
}
|
||||
}
|
||||
|
||||
// Throw clean exception when no content is provided Fix #23
|
||||
if (content == null) {
|
||||
throw new MapperParsingException("No content is provided.");
|
||||
}
|
||||
|
||||
Metadata metadata = new Metadata();
|
||||
if (contentType != null) {
|
||||
metadata.add(Metadata.CONTENT_TYPE, contentType);
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.action.count.CountResponse;
|
|||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.network.NetworkUtils;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
|
@ -133,4 +134,19 @@ public class SimpleAttachmentIntegrationTests {
|
|||
countResponse = node.client().count(countRequest("test").query(fieldQuery("file", "End"))).actionGet();
|
||||
assertThat(countResponse.count(), equalTo(1l));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for issue https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/23
|
||||
* <br/>We throw a nicer exception when no content is provided
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test(expectedExceptions = MapperParsingException.class)
|
||||
public void testNoContent() throws Exception {
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
|
||||
|
||||
node.client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
|
||||
node.client().index(indexRequest("test").type("person")
|
||||
.source(jsonBuilder().startObject().field("file").startObject().endObject())).actionGet();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue