Skip to content

Commit 626c897

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 aa1a3c9 commit 626c897

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
@@ -257,7 +257,8 @@ public void onResponse(SearchResponse response) {
257257
}
258258

259259
SearchHits hits = response.getHits();
260-
if (hits.getTotalHits().value == 1) {
260+
// Detectors Index hits count could be more even if we fetch one
261+
if (hits.getTotalHits().value >= 1 && hits.getHits().length > 0) {
261262
try {
262263
SearchHit hit = hits.getAt(0);
263264

@@ -268,6 +269,7 @@ public void onResponse(SearchResponse response) {
268269
Detector detector = Detector.docParse(xcp, hit.getId(), hit.getVersion());
269270
joinEngine.onSearchDetectorResponse(detector, finding);
270271
} catch (IOException e) {
272+
log.error("IOException for request {}", searchRequest.toString(), e);
271273
onFailures(e);
272274
}
273275
} else {

0 commit comments

Comments
 (0)