From d823684348aeeee9c66f25a7e0eaa05301a83c51 Mon Sep 17 00:00:00 2001 From: Jasen Bentley Date: Wed, 9 Oct 2024 17:55:04 -0400 Subject: [PATCH] aerogear-214 : fixes IndexOutOfBounds issue --- .../keycloak/metrics/ResourceExtractor.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jboss/aerogear/keycloak/metrics/ResourceExtractor.java b/src/main/java/org/jboss/aerogear/keycloak/metrics/ResourceExtractor.java index 4f52f5b..9fafca3 100644 --- a/src/main/java/org/jboss/aerogear/keycloak/metrics/ResourceExtractor.java +++ b/src/main/java/org/jboss/aerogear/keycloak/metrics/ResourceExtractor.java @@ -65,21 +65,23 @@ static String getResource(UriInfo uriInfo) { static String getURI(UriInfo uriInfo) { if (URI_METRICS_ENABLED) { List matchedURIs = uriInfo.getMatchedURIs(); - StringBuilder sb = new StringBuilder(); + if (!matchedURIs.isEmpty()) { + StringBuilder sb = new StringBuilder(); - if (URI_METRICS_FILTER != null && URI_METRICS_FILTER.length() != 0) { - String[] filter = URI_METRICS_FILTER.split(","); + if (URI_METRICS_FILTER != null && URI_METRICS_FILTER.length() != 0) { + String[] filter = URI_METRICS_FILTER.split(","); - for (int i = 0; i < filter.length; i++) { - if (matchedURIs.get(0).contains(filter[i])) { + for (int i = 0; i < filter.length; i++) { + if (matchedURIs.get(0).contains(filter[i])) { - sb = getURIDetailed(sb, matchedURIs); + sb = getURIDetailed(sb, matchedURIs); + } } + } else { + sb = getURIDetailed(sb, matchedURIs); } - } else { - sb = getURIDetailed(sb, matchedURIs); + return sb.toString(); } - return sb.toString(); } return ""; }