commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1171062 - in /commons/proper/compress/trunk: ./ src/main/java/org/apache/commons/compress/compressors/pack200/
Date Thu, 15 Sep 2011 11:46:02 GMT
Author: bodewig
Date: Thu Sep 15 11:46:02 2011
New Revision: 1171062

URL: http://svn.apache.org/viewvc?rev=1171062&view=rev
Log:
don't rely on pack/unpack closing the input in exceptional situations

Modified:
    commons/proper/compress/trunk/findbugs-exclude-filter.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200Utils.java

Modified: commons/proper/compress/trunk/findbugs-exclude-filter.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/findbugs-exclude-filter.xml?rev=1171062&r1=1171061&r2=1171062&view=diff
==============================================================================
--- commons/proper/compress/trunk/findbugs-exclude-filter.xml (original)
+++ commons/proper/compress/trunk/findbugs-exclude-filter.xml Thu Sep 15 11:46:02 2011
@@ -71,6 +71,11 @@
     <Method name="&lt;init&gt;" />
     <Bug pattern="DE_MIGHT_IGNORE" />
   </Match>
+  <Match>
+    <Class name="org.apache.commons.compress.compressors.pack200.Pack200CompressorOutputStream"
/>
+    <Method name="finish" />
+    <Bug pattern="DE_MIGHT_IGNORE" />
+  </Match>
 
   <!-- Reason: skip(Long.MAX_VALUE) called to drain stream completely,
        the class overrides skip to ensure it reads the full amount

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorOutputStream.java?rev=1171062&r1=1171061&r2=1171062&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200CompressorOutputStream.java
Thu Sep 15 11:46:02 2011
@@ -120,8 +120,21 @@ public class Pack200CompressorOutputStre
             if (properties != null) {
                 p.properties().putAll(properties);
             }
-            p.pack(new JarInputStream(streamBridge.getInput()),
-                   originalOutput);
+            JarInputStream ji = null;
+            boolean success = false;
+            try {
+                p.pack(ji = new JarInputStream(streamBridge.getInput()),
+                       originalOutput);
+                success = true;
+            } finally {
+                if (!success && ji != null) {
+                    try {
+                        ji.close();
+                    } catch (IOException ex) { // NOPMD
+                        // swallow so original exception isn't masked
+                    }
+                }
+            }
         }
     }
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200Utils.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200Utils.java?rev=1171062&r1=1171061&r2=1171062&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200Utils.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/pack200/Pack200Utils.java
Thu Sep 15 11:46:02 2011
@@ -62,10 +62,12 @@ public class Pack200Utils {
         f.deleteOnExit();
         try {
             OutputStream os = new FileOutputStream(f);
+            JarFile j = null;
             try {
                 Pack200.Packer p = Pack200.newPacker();
                 p.properties().putAll(props);
-                p.pack(new JarFile(from), os);
+                p.pack(j = new JarFile(from), os);
+                j = null;
                 os.close();
                 os = null;
 
@@ -73,6 +75,9 @@ public class Pack200Utils {
                 os = new JarOutputStream(new FileOutputStream(to));
                 u.unpack(f, (JarOutputStream) os);
             } finally {
+                if (j != null) {
+                    j.close();
+                }
                 if (os != null) {
                     os.close();
                 }



Mime
View raw message