You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Rob Outar <ro...@ideorlando.org> on 2003/06/04 18:07:32 UTC

java.lang.IllegalArgumentException: attempt to access a deleted document

Hi all,

	I have written a GUI program that looks for files on a given file system
that are not in the index and vice versa, files that are in the index but no
on the file system.  It is basically finds orphan files.  We do not want
files on the file system that are not in the index and documents in the
index that do not have a corresponding physical file on the file system.

	In the former case I get a list of all the files on the file system and
look in the index for the corresponding Document.  In the latter case I get
a list of all documents and then look for the files on the file system.
During this process I get the above exception.  Has anyone seen this before?
I am not sure how I am trying to access a deleted document, I think the
problem might be in the below code:

 public synchronized String[] getDocuments() throws IOException {

        IndexReader reader = null;
        try {
            reader = IndexReader.open(this.indexLocation);
            int numOfDocs      = reader.numDocs();
            String[] docs      = new String[numOfDocs];
            Document doc       = null;

            for (int i = 0; i < numOfDocs; i++) {
                doc = reader.document(i);
                docs[i] = doc.get(SearchEngineConstants.REPOSITORY_PATH);
            }
            return docs;
        }
        finally {
            if (reader != null) {
                reader.close();
            }
        }
    }

but I am not sure.

Any help would be appreciated.

Thanks,

Rob


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


RE: java.lang.IllegalArgumentException: attempt to access a deleted document

Posted by Rob Outar <ro...@ideorlando.org>.
I added the following code:

   for (int i = 0; i < numOfDocs; i++) {
                if ( !reader.isDeleted(i)) {
                    doc = reader.document(i);
                    docs[i] =
doc.get(SearchEngineConstants.REPOSITORY_PATH);
                }
            }
            return docs;

but it never goes in the if statement, for every value of i, isDeleted(i) is
returning true?!?  Am I doing something wrong?  I was trying to do what Doug
outlined below.


Thanks,

Rob
-----Original Message-----
From: Doug Cutting [mailto:cutting@lucene.com]
Sent: Wednesday, June 04, 2003 12:34 PM
To: Lucene Users List
Subject: Re: java.lang.IllegalArgumentException: attempt to access a
deleted document


Rob Outar wrote:
>  public synchronized String[] getDocuments() throws IOException {
>
>         IndexReader reader = null;
>         try {
>             reader = IndexReader.open(this.indexLocation);
>             int numOfDocs      = reader.numDocs();
>             String[] docs      = new String[numOfDocs];
>             Document doc       = null;
>
>             for (int i = 0; i < numOfDocs; i++) {
>                 doc = reader.document(i);
>                 docs[i] = doc.get(SearchEngineConstants.REPOSITORY_PATH);
>             }
>             return docs;
>         }
>         finally {
>             if (reader != null) {
>                 reader.close();
>             }
>         }
>     }

The limit of your iteration should be IndexReader.maxDoc(), not
IndexReader.numDocs():

http://jakarta.apache.org/lucene/docs/api/org/apache/lucene/index/IndexReade
r.html#maxDoc()

Also, you should first check that each document is not deleted before
calling IndexReader.document(int):

http://jakarta.apache.org/lucene/docs/api/org/apache/lucene/index/IndexReade
r.html#isDeleted(int)

Doug


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: java.lang.IllegalArgumentException: attempt to access a deleted document

Posted by Doug Cutting <cu...@lucene.com>.
Rob Outar wrote:
>  public synchronized String[] getDocuments() throws IOException {
> 
>         IndexReader reader = null;
>         try {
>             reader = IndexReader.open(this.indexLocation);
>             int numOfDocs      = reader.numDocs();
>             String[] docs      = new String[numOfDocs];
>             Document doc       = null;
> 
>             for (int i = 0; i < numOfDocs; i++) {
>                 doc = reader.document(i);
>                 docs[i] = doc.get(SearchEngineConstants.REPOSITORY_PATH);
>             }
>             return docs;
>         }
>         finally {
>             if (reader != null) {
>                 reader.close();
>             }
>         }
>     }

The limit of your iteration should be IndexReader.maxDoc(), not 
IndexReader.numDocs():

http://jakarta.apache.org/lucene/docs/api/org/apache/lucene/index/IndexReader.html#maxDoc()

Also, you should first check that each document is not deleted before 
calling IndexReader.document(int):

http://jakarta.apache.org/lucene/docs/api/org/apache/lucene/index/IndexReader.html#isDeleted(int)

Doug


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org