You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/03/15 12:16:51 UTC

[GitHub] [commons-vfs] garydgregory commented on a change in pull request #167: Fix NPE when closing a stream from a different thread

garydgregory commented on a change in pull request #167:
URL: https://github.com/apache/commons-vfs/pull/167#discussion_r594284827



##########
File path: commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/DefaultFileContentTest.java
##########
@@ -167,4 +174,28 @@ public void testOutputStreamBufferSizeNegativeWithAppendFlag() throws Exception
         }
     }
 
+    @Test
+    public void testOutputStreamClosedInADifferentThread() throws Exception {
+        testStreamClosedInADifferentThread(content -> content.getOutputStream());
+    }
+
+    private <T extends Closeable> void testStreamClosedInADifferentThread(FailableFunction<FileContent, T, IOException> getStream) throws Exception {
+        final File temp = File.createTempFile("temp-file-name", ".tmp");
+        final FileSystemManager fileSystemManager = VFS.getManager();
+
+        try (FileObject file = fileSystemManager.resolveFile(temp.getAbsolutePath())) {
+            T stream = getStream.apply(file.getContent());
+            boolean[] check = { false };

Review comment:
       You no longer need the array hack since AtomicBoolean was introduced in Java 7.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org