You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ec...@apache.org on 2014/11/03 01:24:03 UTC

svn commit: r1636224 - in /commons/proper/vfs/trunk: core/src/main/java/org/apache/commons/vfs2/util/MonitorOutputStream.java src/changes/changes.xml

Author: ecki
Date: Mon Nov  3 00:24:02 2014
New Revision: 1636224

URL: http://svn.apache.org/r1636224
Log:
[VFS-521][RAM][Tests] Fix MonitorOutputStream for Java 8

Modified:
    commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/util/MonitorOutputStream.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/util/MonitorOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/util/MonitorOutputStream.java?rev=1636224&r1=1636223&r2=1636224&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/util/MonitorOutputStream.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/util/MonitorOutputStream.java Mon Nov  3 00:24:02 2014
@@ -19,6 +19,7 @@ package org.apache.commons.vfs2.util;
 import java.io.BufferedOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.commons.vfs2.FileSystemException;
 
@@ -28,7 +29,7 @@ import org.apache.commons.vfs2.FileSyste
 public class MonitorOutputStream
     extends BufferedOutputStream
 {
-    private boolean finished;
+    private final AtomicBoolean finished = new AtomicBoolean(false);
 
     public MonitorOutputStream(final OutputStream out)
     {
@@ -37,21 +38,42 @@ public class MonitorOutputStream
 
     /**
      * Closes this output stream.
+     * <p>
+     * This makes sure the buffers are flushed, close the output
+     * stream and it will call {@link #onClose()}
+     * and re-throw last exception from any of the three.
+     * <p>
+     * This does nothing if the stream is closed already.
+     *
      * @throws IOException if an error occurs.
      */
     @Override
     public void close() throws IOException
     {
-        if (finished)
+        // do not use super.close()
+        // on Java 8 it might throw self suppression, see JDK-8042377
+        // in older Java it silently ignores flush() errors
+        if (finished.getAndSet(true))
         {
             return;
         }
 
-        // Close the output stream
         IOException exc = null;
+
+        // flush the buffer and out stream
         try
         {
-            super.close();
+            super.flush();
+        }
+        catch (final IOException ioe)
+        {
+            exc = ioe;
+        }
+
+        // close the out stream without using super.close()
+        try
+        {
+            super.out.close();
         }
         catch (final IOException ioe)
         {
@@ -68,8 +90,6 @@ public class MonitorOutputStream
             exc = ioe;
         }
 
-        finished = true;
-
         if (exc != null)
         {
             throw exc;
@@ -132,12 +152,12 @@ public class MonitorOutputStream
      * This is a workaround for an oddity with Java's BufferedOutputStream where you can write to
      * even if the stream has been closed.
      *
-     * @throws FileSystemException if an error occurs.
+     * @throws FileSystemException if already closed.
      * @since 2.0
      */
     protected void assertOpen() throws FileSystemException
     {
-        if (finished)
+        if (finished.get())
         {
             throw new FileSystemException("vfs.provider/closed.error");
         }

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1636224&r1=1636223&r2=1636224&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Mon Nov  3 00:24:02 2014
@@ -26,6 +26,10 @@
 <!--       <action issue="VFS-443" dev="ggregory" type="update" due-to="nickallen"> -->
 <!--     	[Local] Need an easy way to convert from a FileObject to a File. -->
 <!--       </action> -->
+      <action issue="VFS-521" dev="ecki" type="fix">
+       [Ram][Tests] Make RAM provider test pass on Java 8
+       (JDK-8042377, self-suppression not permitted, MonitorOutputStream#close()).
+      </action>
       <action issue="VFS-542" dev="ggregory" type="update">
        Update Jsch from 0.1.50 to 0.1.51.
       </action>