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(); module = new Module();
modules.put(name, module); modules.put(name, module);
module.read(dis); 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) { if (module.offset == null) {
//This should not happen. bug 59858 //This should not happen. bug 59858
throw new IOException("Module offset for '" + name + "' was never read."); throw new IOException("Module offset for '" + name + "' was never read.");

View File

@ -255,23 +255,13 @@ public class TestVBAMacroReader {
assertContains(macros.get("Module20"), "here start of superscripting"); 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 @Test
public void bug59858() throws IOException { public void bug59858() throws IOException {
try { File f = POIDataSamples.getSpreadSheetInstance().getFile("59830.xls");
fromFile(POIDataSamples.getSpreadSheetInstance(), "59858.xls"); VBAMacroReader r = new VBAMacroReader(f);
testPassesNow(59858); Map<String, String> macros = r.readMacros();
} catch (IOException e) { assertNotNull(macros.get("Module20"));
if (e.getMessage().matches("Module offset for '.+' was never read.")) { assertContains(macros.get("Module20"), "start of superscripting");
//e.printStackTrace();
// NPE when reading module.offset in VBAMacroReader.readMacros (approx line 258)
skipTest(e);
} else {
// something unexpected failed
throw e;
}
}
} }
@Test @Test