Skip to content

Commit 044d6fb

Browse files
[BUG] ArrayIndexOutOfBoundsException for inconsistent detector index behavior (#843) (#908)
* 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) Co-authored-by: Megha Goyal <[email protected]>
1 parent 0c32858 commit 044d6fb

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
@@ -222,7 +222,8 @@ public void onResponse(SearchResponse response) {
222222
}
223223

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

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

0 commit comments

Comments
 (0)