[ 
https://issues.apache.org/jira/browse/FINERACT-2822?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18115881#comment-18115881
 ] 

Aleksandar Vidakovic commented on FINERACT-2822:
------------------------------------------------

[~abdalrahmanehab][~mugglekid] ... did any of you check if this bug report 
makes any sense? First: the reference to Zookeeper, don't even understand why 
this should be relevant to this specific issue. Please see my comments on the 
PR... if you actually follow all the execution flows you'll realize that the 
cache names collection is only modified in one place during app startup and 
after that untouched. Instead of the brute force "synchronized" blocks that can 
be quite costly I think we can avoid this all just by making that collection 
unmodifieable... then you can lose all those synchronized keywords. And if for 
any reason that I don't seem to have on the radar we really need some 
concurrency management here: why not using ReentrantLock?

> Prevent concurrent modification of supported cache names
> --------------------------------------------------------
>
>                 Key: FINERACT-2822
>                 URL: https://issues.apache.org/jira/browse/FINERACT-2822
>             Project: Apache Fineract
>          Issue Type: Bug
>            Reporter: pranav
>            Priority: Minor
>
> SpotBugs 4.9.3 reports a potential concurrency issue in
> SpecifiedCacheSupportingCacheManager after the JDK upgrade from JDK 17 to JDK 
> 25.
> The supportedCacheNames field is a LinkedHashSet that can be accessed
> concurrently.
> setSupportedCaches() modifies the set while getCacheNames() exposes a
> collection backed by the same set. Concurrent iteration and modification
> can result in ConcurrentModificationException and unsafe concurrent access.
> The implementation should synchronize access to supportedCacheNames and
> return a snapshot from getCacheNames() so callers cannot iterate over the
> internally mutable set while it is being modified.
> A regression test should verify that concurrent reads and updates do not
> throw an exception.
> h3. Steps to reproduce
>  # Create a SpecifiedCachesSupportingCacheManager instance.
>  # Add initial supported cache names.
>  # Start one thread repeatedly calling getCacheNames() and iterating over
>  # Concurrently start another thread repeatedly calling setSupportedCaches()
>  # Concurrent iteration and modification can result in 
> ConcurrentModificationException



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to