title: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException while reading .xlsm file
body: <p>I was trying to read a .xlsm file using apache poi, that runs in a spring boot app (JDK 1.8)</p>
  <p>The following are my entries in build.gradle file</p>
  <pre><code>compile &quot;org.apache.poi:poi:3.17&quot;
  compile &quot;org.apache.poi:poi-ooxml:3.17&quot;
  </code></pre>
  <p>This is the method that tries to read the file within WorkBookProcessor.java class.
  The exception is thrown at the line <strong>workbook = new XSSFWorkbook(file);</strong></p>
  <pre><code>public void saveWorkbook (File file) throws Exception {
  
          XSSFWorkbook workbook = null;
          List&lt;String&gt; error = null;
          try {
               workbook = new XSSFWorkbook(file);
  
              ...... some more code........
  
          } catch (Exception ex) {
              logger.error(&quot;Error:&quot;, ex);
          }
      }
  </code></pre>
  <p>On executing the above code it throws the following execption</p>
  <pre><code>    2020-10-01 11:16:55.909 ERROR 15372 --- [onPool-worker-1] c.b.c.x.p.WorkBookProcessor      : Error:
      
      org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
          at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:63) ~[poi-ooxml-3.17.jar:3.17]
          at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:580) ~[poi-ooxml-3.17.jar:3.17]
          at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:165) ~[poi-ooxml-3.17.jar:3.17]
          at org.apache.poi.xssf.usermodel.XSSFWorkbook.&lt;init&gt;(XSSFWorkbook.java:270) ~[poi-ooxml-3.17.jar:3.17]
          at org.apache.poi.xssf.usermodel.XSSFWorkbook.&lt;init&gt;(XSSFWorkbook.java:323) ~[poi-ooxml-3.17.jar:3.17]
  Caused by: java.lang.reflect.InvocationTargetException: null
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_251]
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_251]
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_251]
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_251]
      at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56) ~[poi-ooxml-3.17.jar:3.17]
      at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:60) ~[poi-ooxml-3.17.jar:3.17]
      ... 14 common frames omitted
  Caused by: java.io.IOException: Zip bomb detected! The file would exceed the max. ratio of compressed file size to the size of the expanded data.
  This may indicate that the file is used to inflate memory usage and thus could pose a security risk.
  You can adjust this limit via ZipSecureFile.setMinInflateRatio() if you need to work with files which exceed this limit.
  Counter: 4099049, cis.counter: 40960, ratio: 0.00999256168930891
  Limits: MIN_INFLATE_RATIO: 0.01
      at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.advance(ZipSecureFile.java:268) ~[poi-ooxml-3.17.jar:3.17]
      at org.apache.poi.openxml4j.util.ZipSecureFile$ThresholdInputStream.read(ZipSecureFile.java:222) ~[poi-ooxml-3.17.jar:3.17]
      at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2919) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:303) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1895) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanQName(XMLEntityScanner.java:843) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanAttribute(XMLNSDocumentScannerImpl.java:409) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:251) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:113) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:142) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:244) ~[na:1.8.0_251]
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339) ~[na:1.8.0_251]
      at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) ~[na:1.8.0_251]
      at org.apache.poi.util.DocumentHelper.readDocument(DocumentHelper.java:140) ~[poi-ooxml-3.17.jar:3.17]
      at org.apache.poi.POIXMLTypeLoader.parse(POIXMLTypeLoader.java:163) ~[poi-ooxml-3.17.jar:3.17]
      at org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument$Factory.parse(Unknown Source) ~[poi-ooxml-schemas-3.17.jar:3.17]
      at org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:192) ~[poi-ooxml-3.17.jar:3.17]
      at org.apache.poi.xssf.model.StylesTable.&lt;init&gt;(StylesTable.java:141) ~[poi-ooxml-3.17.jar:3.17]
      ... 20 common frames omitted
  </code></pre>
  <p>One strange thing is that it works if i re-save the .xlsm file</p>
  <p>On de-bugging further i found that it breaks while reading and parsing the styles.xml file in xl\styles.xml folder.
  The strange thing is that this styles.xml contents is the same as the styles.xml for the .xlsm file that works after re-save.</p>
  <p>Any insights into this issue is highly appreciated.</p>