lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tiago Silveira <>
Subject RAMDirectory and empty indexes
Date Fri, 25 Jun 2004 09:31:10 GMT

I get a NullPointerException when I try to openFile() on a file that
does not yet exist. I don't really know the semantics of the Directory
class, but the javadoc says "Returns a stream reading an existing file."

I traced the problem down to this scenario:

1. The IndexReader wants to open an index that does not yet exist.
2. RAMDirectory gets the openFile(aName) message;
3. RAMDirectory gets the RAMFile from the map with the key aName; when
the file doesn't exist, the map returns null.
4. It creates a RAMInputStream, passing the RAMFile it got (null), and
the first thing RAMInputStream does is to store the size of the file,
calling file.length;
5. When file is null, file.length throws NPE.

Shouldn't RAMDirectory.openFile() create a RAMFile when it is called? I
tried to check this by subclassing Directory, delegating everything to
RAMDirectory and creating the file before returning. The first thing
SegmentInfos does is reading the format from the InputStream, which is
stored as an int. SegmentInfos believes that if it could open the file
from the directory, it's because it is a real segments file, and then:

-----------> read past EOF

Is this the correct behaviour? Where should I check if the Directory
already has an index? And how?

Thank you,
Tiago Silveira

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

View raw message