You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/10/19 16:32:13 UTC

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

Author: jpountz
Date: Mon Oct 19 14:32:13 2015
New Revision: 1709421

URL: http://svn.apache.org/viewvc?rev=1709421&view=rev
Log:
LUCENE-6843: RAMDirectory.listAll() should not return null file names.

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

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java?rev=1709421&r1=1709420&r2=1709421&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/RAMDirectory.java Mon Oct 19 14:32:13 2015
@@ -26,7 +26,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.lucene.util.Accountable;
@@ -111,7 +110,13 @@ public class RAMDirectory extends BaseDi
     // and do not synchronize or anything stronger. it's great for testing!
     // 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.
-    return fileMap.keySet().toArray(new String[fileMap.size()]);
+    // NOTE: don't replace this with return names.toArray(new String[names.size()]);
+    // or some files could be null at the end of the array if files are being deleted
+    // concurrently
+    Set<String> fileNames = fileMap.keySet();
+    List<String> names = new ArrayList<>(fileNames.size());
+    for (String name : fileNames) names.add(name);
+    return names.toArray(new String[names.size()]);
   }
 
   public final boolean fileNameExists(String name) {