From cc7cede7a58b4e1d0eaeb182998de69cad90c15a Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sat, 11 Jun 2016 11:31:12 +0200 Subject: [PATCH] LUCENE-7333: Fix test bug where randomSimpleString() generated a filename that is a reserved device name on Windows --- lucene/CHANGES.txt | 3 +++ .../org/apache/lucene/store/BaseDirectoryTestCase.java | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index fb5d93aeb61..501f2eeb21b 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -147,6 +147,9 @@ Bug Fixes dateline and indexed non-point shapes are much bigger than the heatmap region. (David Smiley) +* LUCENE-7333: Fix test bug where randomSimpleString() generated a filename + that is a reserved device name on Windows. (Uwe Schindler, Mike McCandless) + Other * LUCENE-7295: TermAutomatonQuery.hashCode calculates Automaton.toDot().hash, diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java index 44c03ea4b7e..5ca8a8662af 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java @@ -33,6 +33,7 @@ import java.util.Set; import java.util.zip.CRC32; import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.IndexNotFoundException; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; @@ -1208,10 +1209,8 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase { // Keep trying until virus checker refuses to delete: final String fileName; while (true) { - String candidate = TestUtil.randomSimpleString(random()); - if (candidate.length() == 0) { - continue; - } + // create a random filename (segment file name style), so it cannot hit windows problem with special filenames ("con", "com1",...): + String candidate = IndexFileNames.segmentFileName(TestUtil.randomSimpleString(random(), 1, 6), TestUtil.randomSimpleString(random()), "test"); try (IndexOutput out = dir.createOutput(candidate, IOContext.DEFAULT)) { out.getFilePointer(); // just fake access to prevent compiler warning }