BUG 59858 -- avoid npe when there's a collision of record names

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765479 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tim Allison 2016-10-18 16:43:20 +00:00
parent c878e39b55
commit 92eb3bbade
2 changed files with 7 additions and 17 deletions

View File

@ -218,7 +218,7 @@ public class VBAMacroReader implements Closeable {
module = new Module();
modules.put(name, module);
module.read(dis);
} else {
} else if (module.buf == null) { //if we haven't already read the bytes for the module keyed off this name...
if (module.offset == null) {
//This should not happen. bug 59858
throw new IOException("Module offset for '" + name + "' was never read.");

View File

@ -254,24 +254,14 @@ public class TestVBAMacroReader {
assertNotNull(macros.get("Module20"));
assertContains(macros.get("Module20"), "here start of superscripting");
}
// This test is written as expected-to-fail and should be rewritten
// as expected-to-pass when the bug is fixed.
@Test
public void bug59858() throws IOException {
try {
fromFile(POIDataSamples.getSpreadSheetInstance(), "59858.xls");
testPassesNow(59858);
} catch (IOException e) {
if (e.getMessage().matches("Module offset for '.+' was never read.")) {
//e.printStackTrace();
// NPE when reading module.offset in VBAMacroReader.readMacros (approx line 258)
skipTest(e);
} else {
// something unexpected failed
throw e;
}
}
File f = POIDataSamples.getSpreadSheetInstance().getFile("59830.xls");
VBAMacroReader r = new VBAMacroReader(f);
Map<String, String> macros = r.readMacros();
assertNotNull(macros.get("Module20"));
assertContains(macros.get("Module20"), "start of superscripting");
}
@Test