diff --git a/src/java/org/apache/lucene/search/QueryFilter.java b/src/java/org/apache/lucene/search/QueryFilter.java index dc3b466c6c0..07950179047 100644 --- a/src/java/org/apache/lucene/search/QueryFilter.java +++ b/src/java/org/apache/lucene/search/QueryFilter.java @@ -68,10 +68,12 @@ import org.apache.lucene.index.IndexReader; * QueryFilter that matches, e.g., only documents modified within the last * week. The QueryFilter and RangeQuery would only need to be reconstructed * once per day. + * + * @version $Id$ */ public class QueryFilter extends Filter { private Query query; - private transient WeakHashMap cache = new WeakHashMap(); + private transient WeakHashMap cache = null; /** Constructs a filter which only matches documents matching * query. @@ -82,6 +84,10 @@ public class QueryFilter extends Filter { public BitSet bits(IndexReader reader) throws IOException { + if (cache == null) { + cache = new WeakHashMap(); + } + synchronized (cache) { // check cache BitSet cached = (BitSet) cache.get(reader); if (cached != null) { @@ -97,7 +103,6 @@ public class QueryFilter extends Filter { } }); - synchronized (cache) { // update cache cache.put(reader, bits); }