Fixed empty DocIdSetIterator

Change-Id: I322b10563b92898ce662788277761c356eac9221
diff --git a/.gitignore b/.gitignore
index 149acc4..80db8ed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,4 @@
 /src/test/java/de/ids_mannheim/korap/collection/TestWithExternalIndex.java
 /krill_cache/
 /vc
+/vc-cache
\ No newline at end of file
diff --git a/Changes b/Changes
index 467c752..3e77eb2 100644
--- a/Changes
+++ b/Changes
@@ -1,7 +1,8 @@
-0.63.1 2024-06-24
+0.63.1 2024-08-02
     - [feature] Add fields array to matches in search responses (diewald)
     - [feature] Temporarily add all requested fields in flat legacy fields
       maps (diewald)
+    - [bugfix] Fix empty DocIdSetIterator (margaretha)
 
 0.63.0 2024-06-24
     - [bugfix] Show all inline markers and pagebreaks at match borders (diewald).
diff --git a/src/main/java/de/ids_mannheim/korap/cache/VirtualCorpusCache.java b/src/main/java/de/ids_mannheim/korap/cache/VirtualCorpusCache.java
index 6f93974..e1bef61 100644
--- a/src/main/java/de/ids_mannheim/korap/cache/VirtualCorpusCache.java
+++ b/src/main/java/de/ids_mannheim/korap/cache/VirtualCorpusCache.java
@@ -16,6 +16,8 @@
 import java.util.regex.Pattern;
 
 import org.apache.lucene.index.LeafReaderContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import de.ids_mannheim.korap.IndexInfo;
 import de.ids_mannheim.korap.Krill;
@@ -33,6 +35,9 @@
  */
 public class VirtualCorpusCache {
 
+    public final static Logger log = LoggerFactory
+            .getLogger(VirtualCorpusCache.class);
+    
     public static Pattern vcNamePattern = Pattern.compile("[a-zA-Z0-9]+[a-zA-Z_0-9-.]+");
 
     public static String CACHE_LOCATION = "vc-cache";
@@ -150,7 +155,7 @@
                     return docBitsSupplier.supplyDocBits(context,
                             context.reader().getLiveDocs());
                 }
-                catch (IOException | QueryException e) {
+                catch (Exception e) {
                     throw new RuntimeException(e);
                 }
             });
diff --git a/src/main/java/de/ids_mannheim/korap/collection/VirtualCorpusFilter.java b/src/main/java/de/ids_mannheim/korap/collection/VirtualCorpusFilter.java
index 4d7d9aa..15f9ec6 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/VirtualCorpusFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/VirtualCorpusFilter.java
@@ -4,6 +4,7 @@
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.search.DocIdSet;
+import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.Filter;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.FixedBitSet;
@@ -96,7 +97,10 @@
                 }
             }
             else {
-                bitset.or(docIdSet.iterator());
+                DocIdSetIterator docIdSetIterator = docIdSet.iterator();
+                if (docIdSetIterator != null) {
+                    bitset.or(docIdSetIterator);
+                }
                 if (cbi.isNegative()) {
                     bitset.flip(0, maxDoc);
                 }
diff --git a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java
index da7e158..c5d87f9 100644
--- a/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/collection/TestKrillCollectionIndex.java
@@ -633,6 +633,24 @@
 	};
 	
     @Test
+    public void testEmptyDocIdSetIterator () throws IOException {
+        KrillIndex ki = new KrillIndex();
+        // Indexing test files
+        for (String i : new String[] { "00001", "00002", "00003", "00004",
+                "00005", "00006", "02439" }) {
+            ki.addDoc(getClass().getResourceAsStream("/wiki/" + i + ".json.gz"),
+                    true);
+        };
+        ki.commit();
+
+        String filename = "/queries/collections/vc-ref/query-with-vc-ref-klznkz66.jsonld";
+        String json = getJsonString(getClass().getResource(filename).getFile());
+        KrillCollection kc = new KrillCollection(json);
+        kc.setIndex(ki);
+        assertEquals(0, kc.numberOf("documents"));
+    }
+	
+    @Test
     public void filterExampleFromLegacy () throws Exception {
 
         // Construct index
diff --git a/src/test/resources/queries/collections/named-vcs/klznkz66.jsonld b/src/test/resources/queries/collections/named-vcs/klznkz66.jsonld
new file mode 100644
index 0000000..7ee0064
--- /dev/null
+++ b/src/test/resources/queries/collections/named-vcs/klznkz66.jsonld
@@ -0,0 +1 @@
+{"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld","collection":{"@type":"koral:doc","type":"type:regex","match":"match:eq","key":"corpusSigle","value":"(K|O)[0-9][0-9]","comment":"name:\"klznkz66\",desc:\"klz und nkz 66%\""},"comment":"name:\"klznkz66\",desc:\"klz und nkz 66%\""}
\ No newline at end of file
diff --git a/src/test/resources/queries/collections/vc-ref/query-with-vc-ref-klznkz66.jsonld b/src/test/resources/queries/collections/vc-ref/query-with-vc-ref-klznkz66.jsonld
new file mode 100644
index 0000000..de17c08
--- /dev/null
+++ b/src/test/resources/queries/collections/vc-ref/query-with-vc-ref-klznkz66.jsonld
@@ -0,0 +1 @@
+{"meta":{},"warnings":[],"query":{},"messages":[],"collection":{"@type":"koral:docGroup","operation":"operation:and","operands":[{"ref":"klznkz66","@type":"koral:docGroupRef"},{"@type":"koral:doc","match":"match:eq","type":"type:regex","value":"QAO.*","key":"availability"}]},"@context":"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld","errors":[]}
\ No newline at end of file