Skip to content

Commit

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

* Catch ArrayIndexOutOfBoundsException when detector is missing

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

* Add a check on SearchHits.getHits() length

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

* Remove index out of bounds exception

Signed-off-by: Megha Goyal <goyamegh@amazon.com>

---------

Signed-off-by: Megha Goyal <goyamegh@amazon.com>
(cherry picked from commit 0ef8543)

Co-authored-by: Megha Goyal <56077967+goyamegh@users.noreply.github.com>
  • Loading branch information
opensearch-trigger-bot[bot] and goyamegh committed Mar 12, 2024
1 parent 4f68164 commit 023107f
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,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 @@ -232,6 +233,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 023107f

Please sign in to comment.