Skip to content

Commit

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

* 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)
  • Loading branch information
goyamegh authored and github-actions[bot] committed Feb 14, 2024
1 parent fca29cf commit 15524eb
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);

Check warning on line 276 in src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java#L276

Added line #L276 was not covered by tests
onFailures(e);
}
} else {
Expand Down

0 comments on commit 15524eb

Please sign in to comment.