]> source.dussan.org Git - poi.git/commitdiff
bug 62624 -- ensure streams are closed...thanks to LGTM, and PJ!
authorTim Allison <tallison@apache.org>
Wed, 31 Oct 2018 00:59:16 +0000 (00:59 +0000)
committerTim Allison <tallison@apache.org>
Wed, 31 Oct 2018 00:59:16 +0000 (00:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1845300 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/macros/VBAMacroReader.java

index 6c112c213e1a7c318dac6bc4dac93532e2d924e9..8ba36e7a95829a677f742bb89b9f90590e87061e 100644 (file)
@@ -350,8 +350,9 @@ public class VBAMacroReader implements Closeable {
         for (Entry entry : node) {
             if ("project".equalsIgnoreCase(entry.getName())) {
                 DocumentNode document = (DocumentNode)entry;
-                DocumentInputStream dis = new DocumentInputStream(document);
-                readProjectProperties(dis, moduleNameMap, modules);
+                try(DocumentInputStream dis = new DocumentInputStream(document)) {
+                    readProjectProperties(dis, moduleNameMap, modules);
+                }
             } else if (entry instanceof DirectoryNode) {
                 findProjectProperties((DirectoryNode)entry, moduleNameMap, modules);
             }
@@ -362,8 +363,9 @@ public class VBAMacroReader implements Closeable {
         for (Entry entry : node) {
             if ("projectwm".equalsIgnoreCase(entry.getName())) {
                 DocumentNode document = (DocumentNode)entry;
-                DocumentInputStream dis = new DocumentInputStream(document);
-                readNameMapRecords(dis, moduleNameMap, modules.charset);
+                try(DocumentInputStream dis = new DocumentInputStream(document)) {
+                    readNameMapRecords(dis, moduleNameMap, modules.charset);
+                }
             } else if (entry.isDirectoryEntry()) {
                 findModuleNameMap((DirectoryNode)entry, moduleNameMap, modules);
             }
@@ -485,7 +487,7 @@ public class VBAMacroReader implements Closeable {
         try (DocumentInputStream dis = new DocumentInputStream(dirDocumentNode)) {
             String streamName = null;
             int recordId = 0;
-            boolean inReferenceTwiddled = false;
+
             try (RLEDecompressingInputStream in = new RLEDecompressingInputStream(dis)) {
                 while (true) {
                     recordId = in.readShort();
@@ -620,7 +622,8 @@ public class VBAMacroReader implements Closeable {
 
         if (reserved != reservedByte) {
             if (throwOnUnexpectedReservedByte) {
-                throw new IOException("Expected " + Integer.toHexString(reservedByte) + "after name before Unicode name, but found: " +
+                throw new IOException("Expected " + Integer.toHexString(reservedByte) +
+                        "after name before Unicode name, but found: " +
                         Integer.toHexString(reserved));
             } else {
                 return new ASCIIUnicodeStringPair(ascii, reserved);