Workaround for nullpointer exception in SpanOrQueries

Change-Id: Ie8fc773c5cd88533bed6074ee55ff650b685049b
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
index 63c665e..0cfb938 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/WithinSpans.java
@@ -417,13 +417,32 @@
             this.inSameDoc = false;
             return false;
         };
-        */
+*/
 
         this.more = true;
         this.inSameDoc = true;
 
         this.wrapDoc = this.wrapSpans.doc();
-        this.embeddedDoc = this.embeddedSpans.doc();
+
+        // Last doc was reached
+        if (this.wrapDoc == DocIdSetIterator.NO_MORE_DOCS) {
+            this.more = false;
+            this.matchDoc = DocIdSetIterator.NO_MORE_DOCS;
+            this.inSameDoc = false;
+            return false;
+        };
+
+        // This is just a workaround for an issue that seems to be a bug in Lucene's core code.
+        try {
+            this.embeddedDoc = this.embeddedSpans.doc();
+        }
+        catch (NullPointerException e) {
+            this.more = false;
+            this.matchDoc = DocIdSetIterator.NO_MORE_DOCS;
+            this.inSameDoc = false;
+            return false;
+        };
+        
 
         // Clear all spanStores
         if (this.wrapDoc != this.embeddedDoc) {
@@ -436,13 +455,6 @@
             */
         }
 
-        // Last doc was reached
-        else if (this.wrapDoc == DocIdSetIterator.NO_MORE_DOCS) {
-            this.more = false;
-            this.matchDoc = DocIdSetIterator.NO_MORE_DOCS;
-            this.inSameDoc = false;
-            return false;
-        }
         else {
             if (DEBUG) {
                 log.trace("Current position already is in the same doc");
diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties
index 78bf62e..fd0328d 100644
--- a/src/main/resources/log4j.properties
+++ b/src/main/resources/log4j.properties
@@ -1,4 +1,4 @@
-log4j.rootLogger = ERROR, stdout
+# log4j.rootLogger = ERROR, stdout
 
 # Queries:
 # log4j.logger.de.ids_mannheim.korap.query.SpanNextQuery = TRACE, stdout