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

Early validation of index requests for bulk request #12038

Closed
wants to merge 1 commit into from
Closed

Early validation of index requests for bulk request #12038

wants to merge 1 commit into from

Conversation

jprante
Copy link
Contributor

@jprante jprante commented Jul 5, 2015

In the Java API for adding index requests to a bulk request, the index requests are not validated immediately. This can lead to unexpected NullPointerExceptions when the source is examined.

This pull request adds early validation. It helps to detect bogus index requests before they are sent to the cluster in bulk.

Also, some bulk request test cases are included to check successful validation.

@bleskes
Copy link
Contributor

bleskes commented Jul 6, 2015

Thx @jprante . It feels more inline with the rest of the code to do these things in BulkRequest#validateRequest . Maybe something there this missing (ala a null pointer check)?

@jprante
Copy link
Contributor Author

jprante commented Jul 6, 2015

@bleskes it seems that BulkRequest#validate() is never used in the current code.

@bleskes
Copy link
Contributor

bleskes commented Jul 7, 2015

It should be called by TransportAction#execute(Request, org.elasticsearch.action.ActionListener) . I wonder how you tested?

@jprante
Copy link
Contributor Author

jprante commented Jul 7, 2015

The tests are very simple. NPEs can happen before TransportAction#execute.

ES 1.6 examples how to trigger NPE:

BulkRequestBuilder builder = new BulkRequestBuilder(client)
                .add(Requests.indexRequest());
BulkRequestBuilder builder = new BulkRequestBuilder(client)
                .add((IndexRequest)null);
IndexRequestBuilder r = new IndexRequestBuilder(client);
        BulkRequestBuilder builder = new BulkRequestBuilder(client)
                .add(r.request());
client.prepareBulk()
                .add(Requests.indexRequest().index(null).type(null).id(null))

That is why early validation is needed to reject invalid IndexRequests from being added to a BulkRequest.

@danielmitterdorfer
Copy link
Member

Hi @jprante,

sorry that the feedback took a while. I've checked your examples against the latest master and the only case that is causing trouble (i.e. NPEs) now is: BulkRequestBuilder builder = new BulkRequestBuilder(client, BulkAction.INSTANCE).add((IndexRequest)null);

I agree that it is a programmer error if a null value is passed here. We should fail fast in this case and add a precondition check in BulkRequest#internalAdd() and all other spots where we add a request to the internal collection. As we can rely on Java 7, I'd use `Objects#requireNonNull() from the JDK for the precondition check.

Do want to give it a shot?

@dakrone
Copy link
Member

dakrone commented Apr 6, 2016

Hi @jprante is there still interest in working on this PR?

danielmitterdorfer added a commit to danielmitterdorfer/elasticsearch that referenced this pull request May 14, 2016
With this commit we add a precondition check to BulkRequest so
we fail early if users pass `null` for the request object.

For a more detailed discussion, see elastic#12038.
This supersedes elastic#12038.

Relates elastic#12038.
@danielmitterdorfer
Copy link
Member

I have now created a new PR #18347 that implements the necessary not-null precondition checks and I am closing this PR in favor of the new one.

@danielmitterdorfer danielmitterdorfer removed their assignment May 14, 2016
@lcawl lcawl added :Distributed/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. and removed :Bulk labels Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Distributed/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. stalled
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants