OK I committed an improvement to the 3.6.x javadocs (in case we do a 3.6.1). Thanks!
Mike McCandless http://blog.mikemccandless.com On Fri, May 18, 2012 at 9:37 AM, Edward W. Rouse <ero...@comsquared.com> wrote: > Thanks, I missed that. And the API doc fails to mention it, though it is > pretty standard for a next() method. > >> -----Original Message----- >> From: Michael McCandless [mailto:luc...@mikemccandless.com] >> Sent: Thursday, May 17, 2012 6:20 PM >> To: java-user@lucene.apache.org >> Subject: Re: NullPointerException using IndexReader.termDocs when there >> are no matches >> >> I think you need to pay attention to what td.next() returned; I >> suspect in your case it returned false which means you cannot use any >> of its APIs (.doc(), .freq(), etc.) after that. >> >> Mike McCandless >> >> http://blog.mikemccandless.com >> >> On Thu, May 17, 2012 at 5:52 PM, Edward W. Rouse >> <ero...@comsquared.com> wrote: >> > Lucene 3.6, java 1.6 I get the following: >> > >> > java.lang.NullPointerException at >> > >> org.apache.lucene.index.DirectoryReader$MultiTermDocs.doc(DirectoryRead >> er.ja >> > va:1179) >> > >> > when running this code: >> > >> > IndexReader reader = this.getReader(index); >> > int d = -1; >> > TermDocs td = reader.termDocs(this.createIdTerm(id)); >> > if(td != null) >> > { >> > td.next(); >> > 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. >> > 770-734-5301 >> > >> > >> > >> > >> > --------------------------------------------------------------------- >> > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org >> > For additional commands, e-mail: java-user-h...@lucene.apache.org >> > >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org >> For additional commands, e-mail: java-user-h...@lucene.apache.org > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org