From: Tim Allison Date: Tue, 18 Oct 2016 16:43:20 +0000 (+0000) Subject: BUG 59858 -- avoid npe when there's a collision of record names X-Git-Tag: REL_3_16_BETA1~92 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=64051349494e0722abd477866483fbae29723fe2;p=poi.git 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 --- diff --git a/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java b/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java index d0aa4660c2..21b535b104 100644 --- a/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java +++ b/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java @@ -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."); diff --git a/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java b/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java index f622c54867..3a4c47361d 100644 --- a/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java +++ b/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java @@ -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 macros = r.readMacros(); + assertNotNull(macros.get("Module20")); + assertContains(macros.get("Module20"), "start of superscripting"); } @Test