From 0ef8543b609673bb9ef404ee6c8945725800a080 Mon Sep 17 00:00:00 2001 From: Megha Goyal <56077967+goyamegh@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:57:07 -0800 Subject: [PATCH] [BUG] ArrayIndexOutOfBoundsException for inconsistent detector index behavior (#843) * Catch ArrayIndexOutOfBoundsException when detector is missing Signed-off-by: Megha Goyal * Add a check on SearchHits.getHits() length Signed-off-by: Megha Goyal * Remove index out of bounds exception Signed-off-by: Megha Goyal --------- Signed-off-by: Megha Goyal --- .../transport/TransportCorrelateFindingAction.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java b/src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java index b7a906159..e79af28d3 100644 --- a/src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java +++ b/src/main/java/org/opensearch/securityanalytics/transport/TransportCorrelateFindingAction.java @@ -261,7 +261,8 @@ public void onResponse(SearchResponse response) { } SearchHits hits = response.getHits(); - if (hits.getTotalHits().value == 1) { + // Detectors Index hits count could be more even if we fetch one + if (hits.getTotalHits().value >= 1 && hits.getHits().length > 0) { try { SearchHit hit = hits.getAt(0); @@ -272,6 +273,7 @@ public void onResponse(SearchResponse response) { Detector detector = Detector.docParse(xcp, hit.getId(), hit.getVersion()); joinEngine.onSearchDetectorResponse(detector, finding); } catch (IOException e) { + log.error("IOException for request {}", searchRequest.toString(), e); onFailures(e); } } else {