lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Goller <>
Subject Re: RAMDirectory and empty indexes
Date Fri, 25 Jun 2004 12:40:22 GMT
Tiago Silveira wrote:
> 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? 

Directory.createFile(name) creates a file.
If you call new FileInputStream(file) on a non-existing file you get
an exception too.

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

Try IndexReader.indexExists(directory)
You can create an index with a IndexWriter instance.


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

View raw message