Sorry, but there was a bug in the patch i provided several minutes ago. A NullpointerException can occur in SegmentReader doClose method. The change in the new diff file checks if the ThreadLocal object was created and is not null before trying to get the TermVectorReader from it.

best regards
Bernhard

Index: SegmentReader.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/SegmentReader.java,v
retrieving revision 1.25
diff -u -r1.25 SegmentReader.java
--- SegmentReader.java  11 Aug 2004 17:37:52 -0000      1.25
+++ SegmentReader.java  15 Aug 2004 15:07:47 -0000
@@ -42,8 +42,7 @@
   private FieldsReader fieldsReader;
 
   TermInfosReader tis;
-  TermVectorsReader termVectorsReader;
-
+  
   BitVector deletedDocs = null;
   private boolean deletedDocsDirty = false;
   private boolean normsDirty = false;
@@ -51,6 +50,8 @@
 
   InputStream freqStream;
   InputStream proxStream;
+  
+  private ThreadLocal termVectorsLocal = null;
 
   // Compound File Reader when based on a compound file segment
   CompoundFileReader cfsReader = null;
@@ -128,7 +129,17 @@
     openNorms(cfsDir);
 
     if (fieldInfos.hasVectors()) { // open term vector files only as needed
-      termVectorsReader = new TermVectorsReader(cfsDir, segment, fieldInfos);
+       final Directory dir = cfsDir;
+       termVectorsLocal = new ThreadLocal() {
+               protected synchronized Object initialValue() {
+                       try {
+                               return new TermVectorsReader(dir, segment, fieldInfos);
+                       } catch (IOException ioe) {
+                               ioe.printStackTrace();
+                               return null;
+                       }
+               }
+       };
     }
   }
 
@@ -164,8 +175,13 @@
       proxStream.close();
 
     closeNorms();
-    if (termVectorsReader != null) termVectorsReader.close();
-
+    if (termVectorsLocal != null) {
+       TermVectorsReader termVectorsReader = 
(TermVectorsReader)termVectorsLocal.get();
+       if (termVectorsReader != null) {
+               termVectorsReader.close();
+       }
+    }
+    
     if (cfsReader != null)
       cfsReader.close();
   }
@@ -408,6 +424,15 @@
     FieldInfo fi = fieldInfos.fieldInfo(field);
     if (fi == null || !fi.storeTermVector) return null;
 
+    if (termVectorsLocal == null) {
+       return null;
+    }
+    
+    TermVectorsReader termVectorsReader = (TermVectorsReader)termVectorsLocal.get();
+       if (termVectorsReader == null) {
+               return null;
+       }
+
     return termVectorsReader.get(docNumber, field);
   }
 
@@ -419,9 +444,14 @@
    *  If no such fields existed, the method returns null.
    */
   public TermFreqVector[] getTermFreqVectors(int docNumber) {
-    if (termVectorsReader == null)
-      return null;
-
+       if (termVectorsLocal == null) {
+       return null;
+    }
+       
+       TermVectorsReader termVectorsReader = 
(TermVectorsReader)termVectorsLocal.get();
+       if (termVectorsReader == null) {
+               return null;
+       }
     return termVectorsReader.get(docNumber);
   }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to