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

[3.0] Bugfix: java.util.ConcurrentModificationException at IdentityMa… #1291

Open
wants to merge 1 commit into
base: 3.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,11 @@ public void invalidateQueryCache(Class classThatChanged) {
}
Set invalidations = this.queryResultsInvalidationsByClass.get(classThatChanged);
if (invalidations != null) {
for (Object queryKey : invalidations) {
this.queryResults.remove(queryKey);
synchronized (this.queryResults) {
for (Object queryKey : invalidations) {
this.queryResults.remove(queryKey);

Choose a reason for hiding this comment

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

The queryResults is a ConcurrentHashMap. Could be rewritten to if (this.queryResults.keySet().removeAll(invalidations) invalidations.clear() so that locking is avoided?

Copy link
Author

Choose a reason for hiding this comment

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

Problem is modification of invalidations while it's iterating.
The code can be rewritten according to your suggestion, but this will not eliminate the need of synchronization. Internally java.util.concurrent.ConcurrentHashMap.CollectionView#removeAll can iterate invalidations allso.

PS If invalidations.size() > queryResults.size() the CollectionView#removeAll will work faster then for (Object queryKey : invalidations) {}.

}
invalidations.clear();
}
}
Class superClass = classThatChanged.getSuperclass();
Expand Down