Skip to content

Commit

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

* 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]>
(cherry picked from commit 0ef8543)

Co-authored-by: Megha Goyal <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and goyamegh authored Mar 7, 2024
1 parent a442d0c commit 8c1c08f
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 8c1c08f

Please sign in to comment.