bug 62624 -- ensure streams are closed...thanks to LGTM, and PJ!

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1845300 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tim Allison 2018-10-31 00:59:16 +00:00
parent c257dd71f9
commit fd125b9e4e

View File

@ -350,8 +350,9 @@ public class VBAMacroReader implements Closeable {
for (Entry entry : node) { for (Entry entry : node) {
if ("project".equalsIgnoreCase(entry.getName())) { if ("project".equalsIgnoreCase(entry.getName())) {
DocumentNode document = (DocumentNode)entry; DocumentNode document = (DocumentNode)entry;
DocumentInputStream dis = new DocumentInputStream(document); try(DocumentInputStream dis = new DocumentInputStream(document)) {
readProjectProperties(dis, moduleNameMap, modules); readProjectProperties(dis, moduleNameMap, modules);
}
} else if (entry instanceof DirectoryNode) { } else if (entry instanceof DirectoryNode) {
findProjectProperties((DirectoryNode)entry, moduleNameMap, modules); findProjectProperties((DirectoryNode)entry, moduleNameMap, modules);
} }
@ -362,8 +363,9 @@ public class VBAMacroReader implements Closeable {
for (Entry entry : node) { for (Entry entry : node) {
if ("projectwm".equalsIgnoreCase(entry.getName())) { if ("projectwm".equalsIgnoreCase(entry.getName())) {
DocumentNode document = (DocumentNode)entry; DocumentNode document = (DocumentNode)entry;
DocumentInputStream dis = new DocumentInputStream(document); try(DocumentInputStream dis = new DocumentInputStream(document)) {
readNameMapRecords(dis, moduleNameMap, modules.charset); readNameMapRecords(dis, moduleNameMap, modules.charset);
}
} else if (entry.isDirectoryEntry()) { } else if (entry.isDirectoryEntry()) {
findModuleNameMap((DirectoryNode)entry, moduleNameMap, modules); findModuleNameMap((DirectoryNode)entry, moduleNameMap, modules);
} }
@ -485,7 +487,7 @@ public class VBAMacroReader implements Closeable {
try (DocumentInputStream dis = new DocumentInputStream(dirDocumentNode)) { try (DocumentInputStream dis = new DocumentInputStream(dirDocumentNode)) {
String streamName = null; String streamName = null;
int recordId = 0; int recordId = 0;
boolean inReferenceTwiddled = false;
try (RLEDecompressingInputStream in = new RLEDecompressingInputStream(dis)) { try (RLEDecompressingInputStream in = new RLEDecompressingInputStream(dis)) {
while (true) { while (true) {
recordId = in.readShort(); recordId = in.readShort();
@ -620,7 +622,8 @@ public class VBAMacroReader implements Closeable {
if (reserved != reservedByte) { if (reserved != reservedByte) {
if (throwOnUnexpectedReservedByte) { 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)); Integer.toHexString(reserved));
} else { } else {
return new ASCIIUnicodeStringPair(ascii, reserved); return new ASCIIUnicodeStringPair(ascii, reserved);