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

Issue #12725 reset match indexes for FilterMappings on setFilterMappings #12734

Open
wants to merge 1 commit into
base: jetty-12.0.x
Choose a base branch
from

Conversation

janbartel
Copy link
Contributor

This is an alternative fix for PR #12725.

When a user calls ServletHandler.setFilterMappings(FilterMapping[]) this is like a reset of any FilterMappings that may have existed previously, either by a previous call to the same method, or importantly via a call to addFilterMapping(FilterMapping). When addFilterMapping(FilterMapping) is called, we need to calculate where it should be added, as the servlet spec allows for pre or postpending to existing FilterMappings. We maintain 2 indexes _matchBeforeIndex and _matchAfterIndex to help us determine where to insert the added FilterMapping.

As setFilterMappings([FilterMapping[]) is essentially a reset, these 2 indexes need to be reset too.

@@ -1395,6 +1395,8 @@ public void setFilterMappings(FilterMapping[] filterMappings)
if (isRunning())
updateMappings();
invalidateChainsCache();
_matchBeforeIndex = -1;
Copy link

Choose a reason for hiding this comment

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

Further up in the code, there's this line: List<FilterMapping> mappings = filterMappings == null ? Collections.emptyList() : Arrays.asList(filterMappings); With that being the case, do we always want to reset the indexes to -1 or would we want to determine the correct indexes by looking at the size of the mappings list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kshep92 currently addFilterMapping(FilterMapping) handles all of the calculation of the indexes - if nobody calls this method, then the values of the index are kind of moot.

Copy link

Choose a reason for hiding this comment

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

@janbartel Ok, got it.

@janbartel janbartel requested a review from gregw January 29, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants