From 9355ec4bdaf4eceaa112949a5f187322f421f69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Mora=20L=C3=B3pez?= Date: Tue, 28 May 2024 16:48:37 +0300 Subject: [PATCH] fix: correct conditional check for IP info search results Updated the `getIpInfo` method to fix the conditional check when evaluating the total hits from the Elasticsearch search result. Changed the condition from `hits.total().value() < 0` to `hits.total().value() <= 0` to correctly handle cases where no search results are found, preventing potential `IndexOutOfBoundsException`. --- .../java/com/park/utmstack/service/ip_info/IpInfoService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/park/utmstack/service/ip_info/IpInfoService.java b/backend/src/main/java/com/park/utmstack/service/ip_info/IpInfoService.java index 017e85042..3ece554cb 100644 --- a/backend/src/main/java/com/park/utmstack/service/ip_info/IpInfoService.java +++ b/backend/src/main/java/com/park/utmstack/service/ip_info/IpInfoService.java @@ -44,7 +44,7 @@ public GeoIp getIpInfo(String ip) throws UtmIpInfoException { HitsMetadata hits = elasticsearchService.search(sr, GeoIp.class).hits(); - if (hits.total().value() < 0) + if (hits.total().value() <= 0) return null; return hits.hits().get(0).source();