lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r691694 - in /lucene/java/trunk/src: java/org/apache/lucene/store/RAMOutputStream.java test/org/apache/lucene/index/TestIndexWriter.java
Date Wed, 03 Sep 2008 17:34:30 GMT
Author: mikemccand
Date: Wed Sep  3 10:34:29 2008
New Revision: 691694

URL: http://svn.apache.org/viewvc?rev=691694&view=rev
Log:
LUCENE-1374: fix test case to close reader/writer in try/finally; add assert b!=null in RAMOutputStream.writeBytes
(matches FSIndexOutput which hits NPE)

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/store/RAMOutputStream.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/RAMOutputStream.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/RAMOutputStream.java?rev=691694&r1=691693&r2=691694&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/RAMOutputStream.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/RAMOutputStream.java Wed Sep  3 10:34:29
2008
@@ -108,6 +108,7 @@
   }
 
   public void writeBytes(byte[] b, int offset, int len) throws IOException {
+    assert b != null;
     while (len > 0) {
       if (bufferPosition ==  bufferLength) {
         currentBufferIndex++;

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=691694&r1=691693&r2=691694&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Wed Sep  3 10:34:29
2008
@@ -4087,24 +4087,31 @@
         // different fields, so bulk merge of stored fields
         // cannot run:
         IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), i==0, IndexWriter.MaxFieldLength.UNLIMITED);
-        w.setMergeFactor(5);
-        w.setMergeScheduler(new SerialMergeScheduler());
-        Document doc = new Document();
-        doc.add(new Field("test1", "this is some data that will be compressed this this this",
Field.Store.COMPRESS, Field.Index.NO));
-        doc.add(new Field("test2", new byte[20], Field.Store.COMPRESS));
-        doc.add(new Field("field" + i, "random field", Field.Store.NO, Field.Index.TOKENIZED));
-        w.addDocument(doc);
-        w.close();
+        try {
+          w.setMergeFactor(5);
+          w.setMergeScheduler(new SerialMergeScheduler());
+          Document doc = new Document();
+          doc.add(new Field("test1", "this is some data that will be compressed this this
this", Field.Store.COMPRESS, Field.Index.NO));
+          doc.add(new Field("test2", new byte[20], Field.Store.COMPRESS));
+          doc.add(new Field("field" + i, "random field", Field.Store.NO, Field.Index.TOKENIZED));
+          w.addDocument(doc);
+        } finally {
+          w.close();
+        }
       }
 
       byte[] cmp = new byte[20];
 
       IndexReader r = IndexReader.open(dir);
-      for(int i=0;i<5;i++) {
-        Document doc = r.document(i);
-        assertEquals("this is some data that will be compressed this this this", doc.getField("test1").stringValue());
-        byte[] b = doc.getField("test2").binaryValue();
-        assertTrue(Arrays.equals(b, cmp));
+      try {
+        for(int i=0;i<5;i++) {
+          Document doc = r.document(i);
+          assertEquals("this is some data that will be compressed this this this", doc.getField("test1").stringValue());
+          byte[] b = doc.getField("test2").binaryValue();
+          assertTrue(Arrays.equals(b, cmp));
+        }
+      } finally {
+        r.close();
       }
     } finally {
       dir.close();



Mime
View raw message