Author: tallison
Date: Tue Oct 18 16:43:20 2016
New Revision: 1765479

URL: http://svn.apache.org/viewvc?rev=1765479&view=rev
Log:
BUG 59858 -- avoid npe when there's a collision of record names

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
    poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java?rev=1765479&r1=1765478&r2=1765479&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java 
(original)
+++ poi/trunk/src/java/org/apache/poi/poifs/macros/VBAMacroReader.java Tue Oct 
18 16:43:20 2016
@@ -218,7 +218,7 @@ public class VBAMacroReader implements C
             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.");

Modified: 
poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java?rev=1765479&r1=1765478&r2=1765479&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java 
(original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/macros/TestVBAMacroReader.java 
Tue Oct 18 16:43:20 2016
@@ -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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to