poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1721470 - in /poi/trunk/src: java/org/apache/poi/sl/usermodel/SlideShowFactory.java ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java
Date Tue, 22 Dec 2015 22:36:43 GMT
Author: centic
Date: Tue Dec 22 22:36:43 2015
New Revision: 1721470

URL: http://svn.apache.org/viewvc?rev=1721470&view=rev
Log:
Fix some cases where file resources were not closed correctly, mostly when Exceptions occur
during opening files

Modified:
    poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java
    poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java

Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java?rev=1721470&r1=1721469&r2=1721470&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java Tue Dec 22 22:36:43
2015
@@ -157,7 +157,6 @@ public class SlideShowFactory {
      *  @throws IOException if an error occurs while reading the data
      *  @throws EncryptedDocumentException If the wrong password is given for a protected
file
      */
-    @SuppressWarnings("resource")
     public static SlideShow<?,?> create(InputStream inp, String password) throws IOException,
EncryptedDocumentException {
         // If clearly doesn't do mark/reset, wrap up
         if (! inp.markSupported()) {
@@ -231,17 +230,25 @@ public class SlideShowFactory {
      *  @throws IOException if an error occurs while reading the data
      *  @throws EncryptedDocumentException If the wrong password is given for a protected
file
      */
-    @SuppressWarnings("resource")
     public static SlideShow<?,?> create(File file, String password, boolean readOnly)
throws IOException, EncryptedDocumentException {
         if (!file.exists()) {
             throw new FileNotFoundException(file.toString());
         }
 
+        NPOIFSFileSystem fs = null;
         try {
-            NPOIFSFileSystem fs = new NPOIFSFileSystem(file, readOnly);
+            fs = new NPOIFSFileSystem(file, readOnly);
             return create(fs, password);
         } catch(OfficeXmlFileException e) {
+            if(fs != null) {
+                fs.close();
+            }
             return createXSLFSlideShow(file, readOnly);
+        } catch(RuntimeException e) {
+            if(fs != null) {
+                fs.close();
+            }
+            throw e;
         }
     }
     

Modified: poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java?rev=1721470&r1=1721469&r2=1721470&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java Tue Dec 22 22:36:43
2015
@@ -278,7 +278,14 @@ public class WorkbookFactory {
 
         try {
             NPOIFSFileSystem fs = new NPOIFSFileSystem(file, readOnly);
-            return create(fs, password);
+            try {
+                return create(fs, password);
+            } catch (RuntimeException e) {
+                // ensure that the file-handle is closed again
+                fs.close();
+                
+                throw e;
+            }
         } catch(OfficeXmlFileException e) {
             // opening as .xls failed => try opening as .xlsx
             OPCPackage pkg = OPCPackage.open(file, readOnly ? PackageAccess.READ : PackageAccess.READ_WRITE);
@@ -291,7 +298,7 @@ public class WorkbookFactory {
 
                 // rethrow exception
                 throw ioe;
-            } catch (IllegalArgumentException ioe) {
+            } catch (RuntimeException ioe) {
                 // ensure that file handles are closed (use revert() to not re-write the
file)
                 pkg.revert();
                 //pkg.close();

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java?rev=1721470&r1=1721469&r2=1721470&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java Tue
Dec 22 22:36:43 2015
@@ -105,6 +105,7 @@ public final class PowerPointExtractor e
     */
    public PowerPointExtractor(NPOIFSFileSystem fs) throws IOException {
       this(fs.getRoot());
+      setFilesystem(fs);
    }
 
    /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message