Apache Lucene open-source search software
LUCENE-6124: fix double-close() bugs in WindowsFS etc
Robert Muir199a90214b54
diff --git a/lucene/test-framework/src/java/org/apache/lucene/mockfile/HandleTrackingFS.java b/lucene/test-framework/src/java/org/apache/lucene/mockfile/HandleTrackingFS.javaindex 12f5f4067fb..8a78faae57e 100644--- a/lucene/test-framework/src/java/org/apache/lucene/mockfile/HandleTrackingFS.java+++ b/lucene/test-framework/src/java/org/apache/lucene/mockfile/HandleTrackingFS.java@@ -93,9 +93,15 @@ public abstract class HandleTrackingFS extends FilterFileSystemProvider {@Overridepublic InputStream newInputStream(Path path, OpenOption... options) throws IOException {InputStream stream = new FilterInputStream2(super.newInputStream(path, options)) {++ boolean closed;+@Overridepublic void close() throws IOException {- onClose(path, this);+ if (!closed) {+ closed = true;+ onClose(path, this);+ }super.close();}@@ -121,9 +127,15 @@ public abstract class HandleTrackingFS extends FilterFileSystemProvider {@Overridepublic OutputStream newOutputStream(final Path path, OpenOption... options) throws IOException {OutputStream stream = new FilterOutputStream2(super.newOutputStream(path, options)) {++ boolean closed;+@Overridepublic void close() throws IOException {- onClose(path, this);+ if (!closed) {+ closed = true;+ onClose(path, this);+ }super.close();}@@ -149,9 +161,15 @@ public abstract class HandleTrackingFS extends FilterFileSystemProvider {@Overridepublic FileChannel newFileChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {FileChannel channel = new FilterFileChannel(super.newFileChannel(path, options, attrs)) {++ boolean closed;+@Overrideprotected void implCloseChannel() throws IOException {- onClose(path, this);+ if (!closed) {+ closed = true;+ onClose(path, this);+ }super.implCloseChannel();}@@ -177,9 +195,15 @@ public abstract class HandleTrackingFS extends FilterFileSystemProvider {@Overridepublic AsynchronousFileChannel newAsynchronousFileChannel(Path path, Set<? extends OpenOption> options, ExecutorService executor, FileAttribute<?>... attrs) throws IOException {AsynchronousFileChannel channel = new FilterAsynchronousFileChannel(super.newAsynchronousFileChannel(path, options, executor, attrs)) {++ boolean closed;+@Overridepublic void close() throws IOException {- onClose(path, this);+ if (!closed) {+ closed = true;+ onClose(path, this);+ }super.close();}@@ -205,9 +229,15 @@ public abstract class HandleTrackingFS extends FilterFileSystemProvider {@Overridepublic SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {SeekableByteChannel channel = new FilterSeekableByteChannel(super.newByteChannel(path, options, attrs)) {++ boolean closed;+@Overridepublic void close() throws IOException {- onClose(path, this);+ if (!closed) {+ closed = true;+ onClose(path, this);+ }super.close();}@@ -237,9 +267,15 @@ public abstract class HandleTrackingFS extends FilterFileSystemProvider {stream = new TrackingSecureDirectoryStream((SecureDirectoryStream<Path>)stream, dir);} else {stream = new FilterDirectoryStream<Path>(stream) {++ boolean closed;+@Overridepublic void close() throws IOException {- onClose(dir, this);+ if (!closed) {+ closed = true;+ onClose(dir, this);+ }super.close();}@@ -271,10 +307,15 @@ public abstract class HandleTrackingFS extends FilterFileSystemProvider {super(delegate);this.dir = dir;}++ boolean closed;@Overridepublic void close() throws IOException {- onClose(dir, this);+ if (!closed) {+ closed = true;+ onClose(dir, this);+ }super.close();}@@ -303,9 +344,15 @@ public abstract class HandleTrackingFS extends FilterFileSystemProvider {@Overridepublic SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {SeekableByteChannel channel = new FilterSeekableByteChannel(super.newByteChannel(path, options, attrs)) {++ boolean closed;+@Overridepublic void close() throws IOException {- onClose(path, this);+ if (!closed) {+ closed = true;+ onClose(path, this);+ }super.close();}