lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Edward W. Rouse" <>
Subject NullPointerException using IndexReader.termDocs when there are no matches
Date Thu, 17 May 2012 21:52:37 GMT
Lucene 3.6, java 1.6 I get the following:

java.lang.NullPointerException at

when running this code:

IndexReader reader = this.getReader(index);
int d = -1;
TermDocs td = reader.termDocs(this.createIdTerm(id));
if(td != null)
  d = td.doc();

private Term createIdTerm(String id)
  return new Term(Constants.DEFAULT_ID_FIELD, id);

At the time this code runs I would expect that td would be null since there
are no documents in the index that match the term, but that is not the case.
Instead I get the NPE when trying td.doc(). I can wrap the code in a
try/catch for that line, but I think there must be a better way to determine
if I got any matches for a Term.

Edward W. Rouse
Comsquared System, Inc.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message