diff options
author | cushon <cushon@google.com> | 2018-01-05 08:29:44 -0800 |
---|---|---|
committer | Ron Shapiro <ronshapiro@google.com> | 2018-01-05 14:35:03 -0500 |
commit | 04300a3bf944f44c9968ee7ab3280097d90ff531 (patch) | |
tree | e0368f1a9693fd91706c5ce5d2393f73c7132f83 | |
parent | 1a432be17f5d5f6b8e96adb11b5280c6d2009a96 (diff) | |
download | jimfs-04300a3bf944f44c9968ee7ab3280097d90ff531.tar.gz |
Ensure streams that encapsulate a closeable resource are closed
This cleanup is being performed in preparation for enabling a
compiler error.
From the javadoc for Files.list:
The returned stream encapsulates a DirectoryStream. If timely disposal
of file system resources is required, the try-with-resources construct
should be used to ensure that the stream's close method is invoked
after the stream operations are completed.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180930883
-rw-r--r-- | jimfs/src/test/java/com/google/common/jimfs/JimfsFileSystemCloseTest.java | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/jimfs/src/test/java/com/google/common/jimfs/JimfsFileSystemCloseTest.java b/jimfs/src/test/java/com/google/common/jimfs/JimfsFileSystemCloseTest.java index 0ac657a..2e05714 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/JimfsFileSystemCloseTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/JimfsFileSystemCloseTest.java @@ -30,11 +30,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -55,6 +50,9 @@ import java.nio.file.WatchService; import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileTime; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** * Tests for what happens when a file system is closed. @@ -154,14 +152,15 @@ public class JimfsFileSystemCloseTest { Path p = fs.getPath("/foo"); Files.createDirectory(p); - DirectoryStream<Path> stream = Files.newDirectoryStream(p); + try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) { - fs.close(); + fs.close(); - try { - stream.iterator(); - fail(); - } catch (ClosedDirectoryStreamException expected) { + try { + stream.iterator(); + fail(); + } catch (ClosedDirectoryStreamException expected) { + } } } |