Skip to content

Commit

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

* 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>
(cherry picked from commit 35aa656)
  • Loading branch information
opensearch-trigger-bot[bot] authored and github-actions[bot] committed Mar 14, 2024
1 parent eb9649e commit b1e339e
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 b1e339e

Please sign in to comment.