From 7d4ba636b0bdb6acb207963d7e9f75402623962a Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 23 Dec 2014 15:45:16 +0000 Subject: [PATCH] LUCENE-6120: Fix MockDirectoryWrapper close() handling git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1647599 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 3 +++ .../apache/lucene/store/MockIndexInputWrapper.java | 12 ++++++------ .../apache/lucene/store/MockIndexOutputWrapper.java | 7 ++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index c9eb8830516..7100e7fa2b1 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -419,6 +419,9 @@ Tests * LUCENE-5968: Improve error message when 'ant beast' is run on top-level modules. (Ramkumar Aiyengar, Uwe Schindler) +* LUCENE-6120: Fix MockDirectoryWrapper's close() handling. + (Mike McCandless, Robert Muir) + Build * LUCENE-5909: Smoke tester now has better command line parsing and diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java index 64fbfdcc90b..82133e9f4ff 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java +++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java @@ -1,5 +1,6 @@ package org.apache.lucene.store; +import java.io.Closeable; import java.io.IOException; import java.util.Map; import java.util.Set; @@ -43,21 +44,20 @@ public class MockIndexInputWrapper extends IndexInput { @Override public void close() throws IOException { + // TODO turn on the following to look for leaks closing inputs, + // after fixing TestTransactions + // dir.maybeThrowDeterministicException(); if (closed) { delegate.close(); // don't mask double-close bugs return; } closed = true; - try { - // turn on the following to look for leaks closing inputs, - // after fixing TestTransactions - // dir.maybeThrowDeterministicException(); - } finally { - delegate.close(); + try (Closeable delegate = this.delegate) { // Pending resolution on LUCENE-686 we may want to // remove the conditional check so we also track that // all clones get closed: + assert delegate != null; if (!isClone) { dir.removeIndexInput(this, name); } diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java index 870c154777c..ad646bf46a4 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java +++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexOutputWrapper.java @@ -17,6 +17,7 @@ package org.apache.lucene.store; * limitations under the License. */ +import java.io.Closeable; import java.io.IOException; import org.apache.lucene.util.LuceneTestCase; @@ -98,10 +99,11 @@ public class MockIndexOutputWrapper extends IndexOutput { } closed = true; - try { + try (Closeable delegate = this.delegate) { + assert delegate != null; dir.maybeThrowDeterministicException(); } finally { - delegate.close(); + dir.removeIndexOutput(this, name); if (dir.trackDiskUsage) { // Now compute actual disk usage & track the maxUsedSize // in the MockDirectoryWrapper: @@ -110,7 +112,6 @@ public class MockIndexOutputWrapper extends IndexOutput { dir.maxUsedSize = size; } } - dir.removeIndexOutput(this, name); } }