Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aerogear-214 : Fixes IndexOutOfBounds issue #218

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

jbentley6
Copy link

@jbentley6 jbentley6 commented Oct 9, 2024

Fixes IndexOutOfBoundsException with keycloak 25 and keycloak-metrics-spi 6.0.0

Motivation

#214

What

Adding a check that matchedURIs is not an empty list to ResourceExtractor.getURI

Why

Currently when using version keycloak-metrics-spi-6.0.0.jar with Keycloak 25 when a call comes into a URI that doesn't have a matching resource uriInfo.getMatchedURIs returns an empty list see https://jakarta.ee/specifications/platform/9/apidocs/jakarta/ws/rs/core/uriinfo#getMatchedURIs--

How

Adding a check to ensure that get(0) is not called on the empty list

Verification Steps

Add the steps required to check this change. Following an example.

  1. Make sure that URI_METRICS_ENABLED is set to true
  2. Navigate to a URL that should be a 404 in keycloak like /thisdoesnotexist
  3. Should no longer see the Internal Server Error page and the IndexOutOfBounds exception in the logs

Checklist:

  • Code has been tested locally by PR requester
  • Changes have been successfully verified by another team member

Progress

  • Finished task
  • TODO

Additional Notes

PS.: Add images and/or .gifs to illustrate what was changed if this pull request modifies the appearance/output of something presented to the users.

@jbentley6
Copy link
Author

@pb82 was wondering if there's anyway to get someone to take a look at this

@alexted
Copy link

alexted commented Nov 7, 2024

@pb82 Could you pay attention to this?

@@ -65,21 +65,23 @@ static String getResource(UriInfo uriInfo) {
static String getURI(UriInfo uriInfo) {
if (URI_METRICS_ENABLED) {
List<String> matchedURIs = uriInfo.getMatchedURIs();
StringBuilder sb = new StringBuilder();
if (!matchedURIs.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense. So previously we would try to access matchedURIs.get(0) even if there were no matched URIs.

@pb82 pb82 merged commit 435ff6f into aerogear:master Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants