Skip to content

Bulk index operation w/o body throws NPE #24701

@httpdigest

Description

@httpdigest

Elasticsearch version: 5.4.0

Plugins installed: []

JVM version (java -version):

java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

OS version (uname -a if on a Unix-like system): Windows 7 x64

Description of the problem including expected versus actual behavior:
When calling the _bulk API to index multiple documents, and not using an actual POST body, the server prints a stacktrace of a NullPointerException and responds with a 'null_pointer_exception' error in the response body.
It is clear that this was a bad request, since the actual data which should be indexed, was missing. But it should not result in a NPE but maybe rather a HTTP Bad Request response code. One could even argue that a bulk index without any data is like a bulk index with 0 data, so it could also be regarded a valid call just without any updated documents.

Steps to reproduce:

  • Download elasticsearch zip from https://www.elastic.co/downloads/elasticsearch
  • Extract the zip somewhere
  • execute bin/elasticsearch.bat
  • use a HTTP client to create an index via POST localhost:9200/exampleindex
  • use a HTTP client to call a bulk index operation via POST localhost:9200/exampleindex/all/_bulk but without a POST body

Provide logs (if relevant):
The following exception stacktrace is printed in the log upon calling the last POST request above:

java.lang.NullPointerException: null
        at org.elasticsearch.action.bulk.BulkRequest.add(BulkRequest.java:318) ~[elasticsearch-5.4.0.jar:5.4.0]
        at org.elasticsearch.rest.action.document.RestBulkAction.prepareRequest(RestBulkAction.java:89) ~[elasticsearch-5.4.0.jar:5.4.0]
        at org.elasticsearch.rest.BaseRestHandler.handleRequest(BaseRestHandler.java:64) ~[elasticsearch-5.4.0.jar:5.4.0]
        at org.elasticsearch.rest.RestController.dispatchRequest(RestController.java:260) ~[elasticsearch-5.4.0.jar:5.4.0]
        at org.elasticsearch.rest.RestController.dispatchRequest(RestController.java:199) [elasticsearch-5.4.0.jar:5.4.0]
        at org.elasticsearch.http.netty4.Netty4HttpServerTransport.dispatchRequest(Netty4HttpServerTransport.java:504) [transport-netty4-5.4.0.jar:5.4.0]
        at org.elasticsearch.http.netty4.Netty4HttpRequestHandler.channelRead0(Netty4HttpRequestHandler.java:72) [transport-netty4-5.4.0.jar:5.4.0]
        at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.9.Final.jar:4.1.9.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.9.Final.jar:4.1.9.Final]

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Core/Infra/REST APIREST infrastructure and utilities:Distributed Indexing/CRUDA catch all label for issues around indexing, updating and getting a doc by id. Not search.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions