Skip to content

Commit f00e44e

Browse files
goyameghgithub-actions[bot]
authored andcommitted
[BUG] ArrayIndexOutOfBoundsException for inconsistent detector index behavior (#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]> (cherry picked from commit 0ef8543)
1 parent 4f68164 commit f00e44e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ public void onResponse(SearchResponse response) {
221221
}
222222

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

@@ -232,6 +233,7 @@ public void onResponse(SearchResponse response) {
232233
Detector detector = Detector.docParse(xcp, hit.getId(), hit.getVersion());
233234
joinEngine.onSearchDetectorResponse(detector, finding);
234235
} catch (IOException e) {
236+
log.error("IOException for request {}", searchRequest.toString(), e);
235237
onFailures(e);
236238
}
237239
} else {

0 commit comments

Comments
 (0)