apache / lucene

Apache Lucene open-source search software
https://lucene.apache.org/
Apache License 2.0
2.69k stars 1.04k forks source link

Unsafe synchronization in CachingWrapperFilterHelper [LUCENE-2520] #3594

Open asfimport opened 14 years ago

asfimport commented 14 years ago

CachingWrapperFilterHelper has unsaft synchronization as follow:

public DocIdSet getDocIdSet(IndexReader reader) throws IOException { if (cache == null) { cache = new WeakHashMap(); }

synchronized (cache) {  
   ...
 }

It is not safe to assgine a new object to cache before synchronizing on. it may results sycnchronize on two different object if the method is called concurrently when cache =null.


Migrated from LUCENE-2520 by Wendy Feng

asfimport commented 14 years ago

Uwe Schindler (@uschindler) (migrated from JIRA)

We discussed several times about that, this is not a problem here, as its a cache and there is no guarantee needed that every object only exists one time. For speed issues in this filter we decided to keep it like that. There are other places in Lucene using caches working the same way.