luozhuang opened a new issue, #12991: URL: https://github.com/apache/lucene/issues/12991
### Description I encountered a NullPointerException when I searched with SpanfirstQuery. The Lucene version is 8.10. The example call stack is ``` A Java Exception: java.lang.NullPointerException at #1 org.apache.lucene.search.spans.SpanScorer.scoreCurrentDoc(SpanScorer.java:76) #2 org.apache.lucene.search.spans.SpanScorer.score(SpanScorer.java:134) #3 com.dummy.search.mySearcher.DocScoreCollector.collect(MyDocScoreCollector.java:59) #4 com.dummy.search.mySearcher.DocScoreCollector$1.collect(MyDocScoreCollector.java:108) #5 org.apache.lucene.search.Weight$DefaultBulkScorer.scoreAll(Weight.java:283) #6 org.apache.lucene.search.Weight$DefaultBulkScorer.score(Weight.java:232) #7 org.apache.lucene.search.BulkScorer.score(BulkScorer.java:39) #8 org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:659) #9 org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:443) ``` The frames #3 and #4 are within my customized collector. This collector has a SpanScorer. The example code of this class looks like ``` public class MyDocScoreCollector implements Collector { ScoreMode collectScore; Scorable scorer; ArrayList<ScoreDoc> scoreDocs = new ArrayList<ScoreDoc>(100); int docBase; public MyDocScoreCollector(boolean collectScore) { if (collectScore) { this.collectScore = ScoreMode.COMPLETE; } else { this.collectScore = ScoreMode.COMPLETE_NO_SCORES; } } public void collect(int doc) throws IOException { float score = 0.0f; if(collectScore==ScoreMode.COMPLETE) score = scorer.score(); ScoreDoc sd = new ScoreDoc(docBase + doc, score); scoreDocs.add(sd); } public void setScorer(Scorable scorer) throws IOException { this.scorer = scorer; } @Override public ScoreMode scoreMode() { return ScoreMode.COMPLETE_NO_SCORES; } public void setNextReader(LeafReaderContext context) throws IOException { this.docBase = context.docBase; } abstract static class ScorerLeafCollector implements LeafCollector { public MyDocScoreCollector docScoreCollector = null; @Override public void setScorer(Scorable scorer) throws IOException { docScoreCollector.setScorer(scorer); } ScorerLeafCollector(MyDocScoreCollector collector) { this.docScoreCollector = collector; } } @Override public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { docBase = context.docBase; return new ScorerLeafCollector(this) { @Override public void setScorer(Scorable scorer) throws IOException { super.setScorer(scorer); } @Override public void collect(int doc) throws IOException { docScoreCollector.collect(doc); } }; } } ``` I found the NullPointerException is caused by the empty **SimScorer** on **SpanWeight**. Due to the empty **SimScorer** on **SpanWeight**, when getting a **SpanScorer** from it, it returns a **SpanScorer** with a null **LeafSimScorer**. Finally, when scoring the doc with the SpanScorer, it encounters the NullPointerException. Within the method SpanScorer.scoreCurrentDoc(), it doesn't check if the **LeafSimScorer** field is null. Instead, only an assertion is there. I also found there is another [similar issue ](https://github.com/apache/lucene/issues/10564)related to the empty **SimScorer** on **SpanWeight**. But it has been fixed by adding some defensive code. Seems this is another similar case. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org