Skip to content

Commit 0ef8543

Browse files
authored
[BUG] ArrayIndexOutOfBoundsException for inconsistent detector index behavior (opensearch-project#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>
1 parent e3362f6 commit 0ef8543

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

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)