You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2010/12/01 16:03:28 UTC

svn commit: r1041039 - /lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMDirectory.java

Author: shaie
Date: Wed Dec  1 15:03:27 2010
New Revision: 1041039

URL: http://svn.apache.org/viewvc?rev=1041039&view=rev
Log:
LUCENE-2779: fix listAll()

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMDirectory.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMDirectory.java?rev=1041039&r1=1041038&r2=1041039&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMDirectory.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/store/RAMDirectory.java Wed Dec  1 15:03:27 2010
@@ -20,8 +20,11 @@ package org.apache.lucene.store;
 import java.io.IOException;
 import java.io.FileNotFoundException;
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -36,7 +39,7 @@ public class RAMDirectory extends Direct
 
   private static final long serialVersionUID = 1l;
 
-  protected Map<String,RAMFile> fileMap = new ConcurrentHashMap<String,RAMFile>();
+  protected final Map<String,RAMFile> fileMap = new ConcurrentHashMap<String,RAMFile>();
   protected final AtomicLong sizeInBytes = new AtomicLong();
   
   // *****
@@ -81,7 +84,12 @@ public class RAMDirectory extends Direct
   @Override
   public final String[] listAll() {
     ensureOpen();
-    return fileMap.keySet().toArray(new String[0]);
+    // NOTE: fileMap.keySet().toArray(new String[0]) is broken in non Sun JDKs,
+    // and the code below is resilient to map changes during the array population.
+    Set<String> fileNames = fileMap.keySet();
+    List<String> names = new ArrayList<String>(fileNames.size());
+    for (String name : fileNames) names.add(name);
+    return names.toArray(new String[names.size()]);
   }
 
   /** Returns true iff the named file exists in this directory. */
@@ -188,6 +196,7 @@ public class RAMDirectory extends Direct
     return new RAMFile(this);
   }
 
+  @Override
   public void sync(Collection<String> names) throws IOException {
   }
 
@@ -206,6 +215,6 @@ public class RAMDirectory extends Direct
   @Override
   public void close() {
     isOpen = false;
-    fileMap = null;
+    fileMap.clear();
   }
 }