Skip to content

Commit

Permalink
StackOverflowError when calling BulkRequest#add (elastic#41672)
Browse files Browse the repository at this point in the history
Removing of payload in BulkRequest (elastic#39843) had a side effect of making
`BulkRequest.add(DocWriteRequest<?>...)` (with varargs) recursive, thus
leading to StackOverflowError. This PR adds a small change in
RequestConvertersTests to show the error and the corresponding fix in
`BulkRequest`.

Fixes elastic#41668
  • Loading branch information
gdarmont authored and hub-cap committed May 4, 2019
1 parent 012a1de commit dc999e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ public void testBulk() throws IOException {
XContentType xContentType = randomFrom(XContentType.JSON, XContentType.SMILE);

int nbItems = randomIntBetween(10, 100);
DocWriteRequest<?>[] requests = new DocWriteRequest<?>[nbItems];
for (int i = 0; i < nbItems; i++) {
String index = randomAlphaOfLength(5);
String id = randomAlphaOfLength(5);
Expand Down Expand Up @@ -913,8 +914,9 @@ public void testBulk() throws IOException {
docWriteRequest.setIfSeqNo(randomNonNegativeLong());
docWriteRequest.setIfPrimaryTerm(randomLongBetween(1, 200));
}
bulkRequest.add(docWriteRequest);
requests[i] = docWriteRequest;
}
bulkRequest.add(requests);

Request request = RequestConverters.bulk(bulkRequest);
assertEquals("/_bulk", request.getEndpoint());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public BulkRequest(@Nullable String globalIndex, @Nullable String globalType) {
*/
public BulkRequest add(DocWriteRequest<?>... requests) {
for (DocWriteRequest<?> request : requests) {
add(request, null);
add(request);
}
return this;
}
Expand Down

0 comments on commit dc999e4

Please sign in to comment.