Hello,

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:

----------->
java.io.IOException: read past EOF
   at org.apache.lucene.store.InputStream.refill(InputStream.java:154)
   at org.apache.lucene.store.InputStream.readByte(InputStream.java:43)
   at org.apache.lucene.store.InputStream.readInt(InputStream.java:73)
   at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:42)
<-----------

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to