[MAGNOLIA-6859] Use of RequestParametersVoter gives ClassCastException Created: 02/Sep/16  Updated: 28/Feb/17  Resolved: 23/Feb/17

Status: Closed
Project: Magnolia
Component/s: cache
Affects Version/s: 5.4.9
Fix Version/s: 5.4.12, 5.5.3

Type: Bug Priority: Neutral
Reporter: Marcus Käppi Assignee: Jaroslav Simak
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Java Source File RequestParametersVoter.java     PNG File cache_config.png     PNG File stacktrace.png    
Issue Links:
Relates
dependency
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Sprint: Kromeriz 84
Story Points: 2

 Description   

Can be reproduced by:
Using standard cache configuration (e.g. the one used on https://demoauthor.magnolia-cms.com), change the node:

/modules/cache/config/contentCaching/defaultPageCache/cachePolicy/shouldBypassVoters/deny/parameters 

to the configuration in the attachment will cause a ClassCastException when visiting any page on public instance. (see attachment)



 Comments   
Comment by Marcus Käppi [ 06/Sep/16 ]

Attached suggested solution.

Comment by Jan Haderka [ 04/Nov/16 ]

While what you propose here will seemingly fix the voter by making it able to accept any parameter not just request, it is likely not correct solution in case of caching & voting. The bypass voters (where you configure RPV according to screenshot) operates on CacheKey and passed down to valuation the request URI. The parameters recorded in the key might be different to those in current request, depending on the implementation of the key, so result from validation performed with modified voter will not be correct in all cases where it will be used.
Instead, the cache policy should be customized in your case to pass (probably to custom subchain) for evaluation also the request parameters recorded by the cache key.

Comment by Roman Kovařík [ 02/Dec/16 ]

Hello buf481,

as you can see in the javadoc of RequestParametersVoter, this voter takes javax.servlet.http.HttpServletRequest as an argument and was never meant to be used with other types.
The cache voters take URI as the argument.
The difference with the other voters (like URIStartsWithVoter) is that those are not typed and take general Object as the argument so work in multiple scenarios.

Best regards
Roman

Generated at Mon Feb 12 04:18:31 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.