]> source.dussan.org Git - poi.git/commitdiff
Avoid NPE in cleanup if NPOIFSFileSystem is opened on a locked File under Windows...
authorNick Burch <nick@apache.org>
Wed, 29 Jul 2015 16:36:32 +0000 (16:36 +0000)
committerNick Burch <nick@apache.org>
Wed, 29 Jul 2015 16:36:32 +0000 (16:36 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1693311 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java

index 9817c3d8186a8ff6cace1207d6beb416276bad53..0bac7e1c7408b84faa9bab9d0fb8814708a2cf7b 100644 (file)
@@ -232,20 +232,21 @@ public class NPOIFSFileSystem extends BlockStore
           // Now process the various entries
           readCoreContents();
        } catch(IOException e) {
-          if(closeChannelOnError) {
-             channel.close();
+          // Until we upgrade to Java 7, and can do a MultiCatch, we 
+          //  need to keep these two catch blocks in sync on their cleanup
+          if (closeChannelOnError && channel != null) {
+              channel.close();
+              channel = null;
           }
           throw e;
        } catch(RuntimeException e) {
           // Comes from Iterators etc.
           // TODO Decide if we can handle these better whilst
           //  still sticking to the iterator contract
-          if(closeChannelOnError) {
-              if (channel != null) {
-                  channel.close();
-                  channel = null;
-              }
-          }
+           if (closeChannelOnError && channel != null) {
+               channel.close();
+               channel = null;
+           }
           throw e;
        }
     }