Skip to content

Commit

Permalink
[BUG] ArrayIndexOutOfBoundsException for inconsistent detector index …
Browse files Browse the repository at this point in the history
…behavior (opensearch-project#843)

* Catch ArrayIndexOutOfBoundsException when detector is missing

Signed-off-by: Megha Goyal <[email protected]>

* Add a check on SearchHits.getHits() length

Signed-off-by: Megha Goyal <[email protected]>

* Remove index out of bounds exception

Signed-off-by: Megha Goyal <[email protected]>

---------

Signed-off-by: Megha Goyal <[email protected]>
  • Loading branch information
goyamegh authored Feb 14, 2024
1 parent e3362f6 commit 0ef8543
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ public void onResponse(SearchResponse response) {
}

SearchHits hits = response.getHits();
if (hits.getTotalHits().value == 1) {
// Detectors Index hits count could be more even if we fetch one
if (hits.getTotalHits().value >= 1 && hits.getHits().length > 0) {
try {
SearchHit hit = hits.getAt(0);

Expand All @@ -272,6 +273,7 @@ public void onResponse(SearchResponse response) {
Detector detector = Detector.docParse(xcp, hit.getId(), hit.getVersion());
joinEngine.onSearchDetectorResponse(detector, finding);
} catch (IOException e) {
log.error("IOException for request {}", searchRequest.toString(), e);
onFailures(e);
}
} else {
Expand Down

0 comments on commit 0ef8543

Please sign in to comment.