lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject svn commit: r732661 - in /lucene/java/trunk/contrib: CHANGES.txt instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexReader.java instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java
Date Thu, 08 Jan 2009 09:28:42 GMT
Author: kalle
Date: Thu Jan  8 01:28:42 2009
New Revision: 732661

URL: http://svn.apache.org/viewvc?rev=732661&view=rev
Log:
LUCENE-1510
InstantiatedIndexReader#norms methods throws NullPointerException on empty index.

Modified:
    lucene/java/trunk/contrib/CHANGES.txt
    lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexReader.java
    lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java

Modified: lucene/java/trunk/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/CHANGES.txt?rev=732661&r1=732660&r2=732661&view=diff
==============================================================================
--- lucene/java/trunk/contrib/CHANGES.txt (original)
+++ lucene/java/trunk/contrib/CHANGES.txt Thu Jan  8 01:28:42 2009
@@ -19,6 +19,9 @@
     same way IndexWriter does. Parts of InstantiatedIndex was not Serializable.
     (Karl Wettin)
 
+ 3. LUCENE-1510: InstantiatedIndexReader#norms methods throws NullPointerException on empty
index.
+    (Karl Wettin, Robert Newson)
+
 New features
 
  1. LUCENE-1470: Added TrieRangeQuery, a much faster implementation of

Modified: lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexReader.java?rev=732661&r1=732660&r2=732661&view=diff
==============================================================================
--- lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexReader.java
(original)
+++ lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndexReader.java
Thu Jan  8 01:28:42 2009
@@ -280,6 +280,9 @@
    */
   public byte[] norms(String field) throws IOException {
     byte[] norms = getIndex().getNormsByFieldNameAndDocumentNumber().get(field);
+    if (norms == null) {
+      return new byte[0]; // todo a static final zero length attribute?
+    }
     if (updatedNormsByFieldNameAndDocumentNumber != null) {
       norms = norms.clone();
       List<NormUpdate> updated = updatedNormsByFieldNameAndDocumentNumber.get(field);
@@ -294,6 +297,9 @@
 
   public void norms(String field, byte[] bytes, int offset) throws IOException {
     byte[] norms = getIndex().getNormsByFieldNameAndDocumentNumber().get(field);
+    if (norms == null) {
+      return;
+    }
     System.arraycopy(norms, 0, bytes, offset, norms.length);
   }
 

Modified: lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java?rev=732661&r1=732660&r2=732661&view=diff
==============================================================================
--- lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java
(original)
+++ lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java
Thu Jan  8 01:28:42 2009
@@ -17,16 +17,19 @@
 package org.apache.lucene.store.instantiated;
 
 import junit.framework.TestCase;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.TopDocCollector;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermEnum;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TopDocCollector;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.RAMDirectory;
 
+import java.util.Arrays;
+import java.io.IOException;
+
 public class TestEmptyIndex extends TestCase {
 
   public void testSearch() throws Exception {
@@ -47,6 +50,38 @@
 
   }
 
+  public void testNorms() throws Exception {
+
+    InstantiatedIndex ii = new InstantiatedIndex();
+    IndexReader r = new InstantiatedIndexReader(ii);
+    testNorms(r);
+    r.close();
+    ii.close();
+
+    // make sure a Directory acts the same
+
+    Directory d = new RAMDirectory();
+    new IndexWriter(d, null, true, IndexWriter.MaxFieldLength.UNLIMITED).close();
+    r = IndexReader.open(d);
+    testNorms(r);
+    r.close();
+    d.close();
+
+  }
+
+  private void testNorms(IndexReader r) throws IOException {
+    byte[] norms;
+    norms = r.norms("foo");
+    assertNotNull(norms);
+    assertEquals(0, norms.length);
+    norms = new byte[10];
+    Arrays.fill(norms, (byte)10);
+    r.norms("foo", norms, 10);
+    for (byte b : norms) {
+      assertEquals((byte)10, b);
+    }
+  }
+
   public void testTermEnum() throws Exception {
 
     InstantiatedIndex ii = new InstantiatedIndex();



Mime
View raw message