Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes b6191970a -> c99d22610


[CXF-6981] Avoid double close in CacheAndWriteOutputStream, patch from Andy 
McCright applied, This closes #179


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c99d2261
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c99d2261
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c99d2261

Branch: refs/heads/3.1.x-fixes
Commit: c99d226104c260943b1d5306889f6fb6b5bcc623
Parents: b619197
Author: Sergey Beryozkin <sberyoz...@gmail.com>
Authored: Thu Oct 13 13:44:14 2016 +0100
Committer: Sergey Beryozkin <sberyoz...@gmail.com>
Committed: Thu Oct 13 13:45:01 2016 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/cxf/io/CachedOutputStream.java   | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c99d2261/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java 
b/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java
index eeced83..9c8175f 100644
--- a/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java
+++ b/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java
@@ -212,8 +212,9 @@ public class CachedOutputStream extends OutputStream {
         }
         doClose();
         currentStream.close();
-        maybeDeleteTempFile(currentStream);
-        postClose();
+        if (!maybeDeleteTempFile(currentStream)) {
+            postClose();
+        }
     }
 
     public boolean equals(Object obj) {
@@ -527,7 +528,8 @@ public class CachedOutputStream extends OutputStream {
             FileUtils.delete(file);
         }
     }
-    private void maybeDeleteTempFile(Object stream) {
+    private boolean maybeDeleteTempFile(Object stream) {
+        boolean postClosedInvoked = false;
         streamList.remove(stream);
         if (!inmem && tempFile != null && streamList.isEmpty() && 
allowDeleteOfFile) {
             if (currentStream != null) {
@@ -537,11 +539,13 @@ public class CachedOutputStream extends OutputStream {
                 } catch (Exception e) {
                     //ignore
                 }
+                postClosedInvoked = true;
             }
             deleteTempFile();
             currentStream = new LoadingByteArrayOutputStream(1024);
             inmem = true;
         }
+        return postClosedInvoked;
     }
 
     public void setOutputDir(File outputDir) throws IOException {

Reply via email to