From 9a536b2c2b62999d2639e0de49e27dd9d2f980a5 Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 20 May 2011 22:16:43 +0300 Subject: [PATCH] NPE when using "not" filter, closes #953. --- .../common/lucene/docset/AllDocSet.java | 4 ++-- .../common/lucene/docset/NotDocIdSet.java | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AllDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AllDocSet.java index eba0b102a4e..69c5ef26f05 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AllDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AllDocSet.java @@ -53,13 +53,13 @@ public class AllDocSet extends DocSet { return new AllDocIdSetIterator(maxDoc); } - private final class AllDocIdSetIterator extends DocIdSetIterator { + public static final class AllDocIdSetIterator extends DocIdSetIterator { private final int maxDoc; private int doc = -1; - private AllDocIdSetIterator(int maxDoc) { + public AllDocIdSetIterator(int maxDoc) { this.maxDoc = maxDoc; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocIdSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocIdSet.java index dab0a6d56b7..d3ae76a4732 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocIdSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocIdSet.java @@ -46,21 +46,22 @@ public class NotDocIdSet extends DocIdSet { } @Override public DocIdSetIterator iterator() throws IOException { - return new NotDocIdSetIterator(); + DocIdSetIterator it = set.iterator(); + if (it == null) { + return new AllDocSet.AllDocIdSetIterator(max); + } + return new NotDocIdSetIterator(max, it); } - class NotDocIdSetIterator extends DocIdSetIterator { + public static class NotDocIdSetIterator extends DocIdSetIterator { + private final int max; + private DocIdSetIterator it1; int lastReturn = -1; - private DocIdSetIterator it1 = null; private int innerDocid = -1; - NotDocIdSetIterator() throws IOException { - initialize(); - } - - private void initialize() throws IOException { - it1 = set.iterator(); - + NotDocIdSetIterator(int max, DocIdSetIterator it) throws IOException { + this.max = max; + this.it1 = it; if ((innerDocid = it1.nextDoc()) == DocIdSetIterator.NO_MORE_DOCS) it1 = null; }