Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Putting a mapping with an empty request body throws a NullPointerException #7536

Closed
dtdesign opened this issue Sep 2, 2014 · 3 comments
Closed

Comments

@dtdesign
Copy link

dtdesign commented Sep 2, 2014

I have been struggling with an issue lately caused by my own fault of providing a valid request body when attempting to add a mapping to an existing index. Attempting to do so will yield a NullPointerException:

[2014-09-01 20:08:31,486][DEBUG][action.admin.indices.mapping.put] [Prototype] failed to put mappings on indices [[my_index]], type [my_type]
java.lang.NullPointerException
    at org.elasticsearch.common.xcontent.XContentFactory.xContent(XContentFactory.java:137)
    at org.elasticsearch.common.xcontent.XContentHelper.convertToMap(XContentHelper.java:113)
    at org.elasticsearch.common.xcontent.XContentHelper.convertToMap(XContentHelper.java:101)
    at org.elasticsearch.index.mapper.DocumentMapperParser.parseCompressed(DocumentMapperParser.java:181)
    at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:387)
    at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:377)
    at org.elasticsearch.cluster.metadata.MetaDataMappingService$5.execute(MetaDataMappingService.java:540)
    at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:309)
    at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:134)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

The issues is caused by https://github.com/elasticsearch/elasticsearch/blob/a059a6574a1c270ccc28ddec1671888fb0cfba28/src/main/java/org/elasticsearch/common/xcontent/XContentFactory.java#L213 which returns null if the input stream is empty. While this is fine, the real problem lies in XContentHelper.convertToMap() which does not properly check for null.

https://github.com/elasticsearch/elasticsearch/blob/a059a6574a1c270ccc28ddec1671888fb0cfba28/src/main/java/org/elasticsearch/common/xcontent/XContentHelper.java#L111-L113

To be fair, this isn't really a bug and I'm more like asking to yield a proper exception in case a developer is as dumb as me and fails to provide a proper request body.

@cfontes
Copy link
Contributor

cfontes commented Sep 4, 2014

Could you provide some examples of the messages you used?

@dtdesign
Copy link
Author

dtdesign commented Sep 5, 2014

@cfontes The request was PUT http://127.0.0.1:9200/my_index/_mapping/my_type, message body had a length of 0.

@rjernst
Copy link
Member

rjernst commented Sep 5, 2014

Found the problem and fixed. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants