Skip to content

Commit 15524eb

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 fca29cf commit 15524eb

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
@@ -261,7 +261,8 @@ public void onResponse(SearchResponse response) {
261261
}
262262

263263
SearchHits hits = response.getHits();
264-
if (hits.getTotalHits().value == 1) {
264+
// Detectors Index hits count could be more even if we fetch one
265+
if (hits.getTotalHits().value >= 1 && hits.getHits().length > 0) {
265266
try {
266267
SearchHit hit = hits.getAt(0);
267268

@@ -272,6 +273,7 @@ public void onResponse(SearchResponse response) {
272273
Detector detector = Detector.docParse(xcp, hit.getId(), hit.getVersion());
273274
joinEngine.onSearchDetectorResponse(detector, finding);
274275
} catch (IOException e) {
276+
log.error("IOException for request {}", searchRequest.toString(), e);
275277
onFailures(e);
276278
}
277279
} else {

0 commit comments

Comments
 (0)