Skip to content

Apache Lucene open-source search software

LUCENE-3057: LuceneTestCase#newFSDirectoryImpl misses to set LockFactory if ctor call throws exception

Simon Willnauerd3c5769911c1
diff --git a/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
index 07ab0fa2618..eef3d2a7781 100644
--- a/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java
@@ -1051,18 +1051,20 @@ public abstract class LuceneTestCase extends Assert {
private static Directory newFSDirectoryImpl(
Class<? extends FSDirectory> clazz, File file, LockFactory lockFactory)
throws IOException {
+ FSDirectory d = null;
try {
// Assuming every FSDirectory has a ctor(File), but not all may take a
// LockFactory too, so setting it afterwards.
Constructor<? extends FSDirectory> ctor = clazz.getConstructor(File.class);
- FSDirectory d = ctor.newInstance(file);
- if (lockFactory != null) {
- d.setLockFactory(lockFactory);
- }
+ d = ctor.newInstance(file);
return d;
} catch (Exception e) {
- return FSDirectory.open(file);
+ d = FSDirectory.open(file);
+ }
+ if (lockFactory != null) {
+ d.setLockFactory(lockFactory);
}
+ return d;
}
static Directory newDirectoryImpl(Random random, String clazzName) {