lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Trejkaz (JIRA)" <>
Subject [jira] [Created] (LUCENE-3326) MoreLikeThis reuses a reader after it has already closed it
Date Mon, 18 Jul 2011 07:03:08 GMT
MoreLikeThis reuses a reader after it has already closed it

                 Key: LUCENE-3326
             Project: Lucene - Java
          Issue Type: Bug
          Components: modules/other
    Affects Versions: 3.3
            Reporter: Trejkaz

MoreLikeThis has a fatal bug whereby it tries to reuse a reader for multiple fields:

    Map<String,Int> words = new HashMap<String,Int>();
    for (int i = 0; i < fieldNames.length; i++) {
        String fieldName = fieldNames[i];
        addTermFrequencies(r, words, fieldName);

However, addTermFrequencies() is creating a TokenStream for this reader:

    TokenStream ts = analyzer.reusableTokenStream(fieldName, r);
    int tokenCount=0;
    // for every token
    CharTermAttribute termAtt = ts.addAttribute(CharTermAttribute.class);
    while (ts.incrementToken()) {
        /* body omitted */

When it closes this analyser, it closes the underlying reader.  Then the second time around
the loop, you get:

Caused by: Stream closed
	at sun.nio.cs.StreamDecoder.ensureOpen(
	at org.apache.lucene.analysis.standard.StandardTokenizerImpl.zzRefill(
	at org.apache.lucene.analysis.standard.StandardTokenizerImpl.getNextToken(
	at org.apache.lucene.analysis.standard.StandardTokenizer.incrementToken(
	at org.apache.lucene.analysis.standard.StandardFilter.incrementTokenClassic(
	at org.apache.lucene.analysis.standard.StandardFilter.incrementToken(
	at org.apache.lucene.analysis.LowerCaseFilter.incrementToken(

My first thought was that it seems like a "ReaderFactory" of sorts should be passed in so
that a new Reader can be created for the second field (maybe the factory could be passed the
field name, so that if someone wanted to pass a different reader to each, they could.)

Interestingly, the methods taking File and URL exhibit the same issue.  I'm not sure what
to do about those (and we're not using them.)  The method taking File could open the file
twice, but the method taking a URL probably shouldn't fetch the same URL twice.

This message is automatically generated by JIRA.
For more information on JIRA, see:


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

View raw message