Apache Lucene open-source search software
LUCENE-3251: Directory#copy leaks file handles
Simon Willnaueraff519123cce
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex cb436c5e2b6..ecfe9c082cb 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -484,6 +484,11 @@ Bug fixes======================= Lucene 3.x (not yet released) ================+Bug fixes++* LUCENE-3251: Directory#copy failed to close target output if opening the+ source stream failed. (Simon Willnauer)+Optimizations* LUCENE-3201, LUCENE-3218: CompoundFileSystem code has been consolidateddiff --git a/lucene/src/java/org/apache/lucene/store/Directory.java b/lucene/src/java/org/apache/lucene/store/Directory.javaindex 33db1a8ed6e..964f502b4e8 100644--- a/lucene/src/java/org/apache/lucene/store/Directory.java+++ b/lucene/src/java/org/apache/lucene/store/Directory.java@@ -224,10 +224,12 @@ public abstract class Directory implements Closeable {* overwrite it if it does.*/public void copy(Directory to, String src, String dest) throws IOException {- IndexOutput os = to.createOutput(dest);- IndexInput is = openInput(src);+ IndexOutput os = null;+ IndexInput is = null;IOException priorException = null;try {+ os = to.createOutput(dest);+ is = openInput(src);is.copyBytes(os, is.length());} catch (IOException ioe) {priorException = ioe;