Uploaded image for project: 'Keikai'
  1. Keikai
  2. KEIKAI-214

Empty protection element causes NPE during import

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 5.2.0
    • 5.1.1
    • Importer
    • Security Level: Jimmy
    • None

      Steps to Reproduce

      Open the attached repro.xslx in importer

      Current Result

       

       Fail to import cell A1 in sheet Sheet1 from book Repro.xlsxCaused by:io.keikai.importer.ImportException: Fail to import cell A1 in sheet Sheet1 from book Repro.xlsx
      	at io.keikai.importer.XlsxImporter.imports(XlsxImporter.java:300)
      	at io.keikai.range.impl.imexp.ExcelImportAdapter.imports(ExcelImportAdapter.java:48)
      	at io.keikai.range.impl.imexp.AbstractImporter.imports(AbstractImporter.java:57)
      	at io.keikai.ui.Spreadsheet.getSBook(Spreadsheet.java:634)
      	at io.keikai.ui.Spreadsheet.getSelectedSSheet(Spreadsheet.java:813)
      	at io.keikai.ui.Spreadsheet.doInvalidate(Spreadsheet.java:2494)
      	at io.keikai.ui.Spreadsheet.invalidate(Spreadsheet.java:2351)
      	at io.keikai.ui.Spreadsheet.setSrc(Spreadsheet.java:853)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      	at java.lang.reflect.Method.invoke(Unknown Source)
      	at org.zkoss.zk.ui.metainfo.Property.assign0(Property.java:332)
      	at org.zkoss.zk.ui.metainfo.Property.assign(Property.java:174)
      	at org.zkoss.zk.ui.metainfo.ComponentInfo.applyProperties(ComponentInfo.java:742)
      	at org.zkoss.zk.ui.impl.AbstractUiFactory.newComponent(AbstractUiFactory.java:146)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:924)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:894)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:781)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:745)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:939)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:894)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:781)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:841)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:799)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:745)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:466)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:374)
      	at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:215)
      	at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:140)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
      	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
      	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
      	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at org.mortbay.jetty.Server.handle(Server.java:326)
      	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
      	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
      	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
      	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
      	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
      Caused by: java.lang.NullPointerException
      	at io.keikai.util.XlsxJsonHelper.toBool(XlsxJsonHelper.java:62)
      	at io.keikai.importer.XlsxExtractor$XlsxProtectionExtractor.isLocked(XlsxExtractor.java:1135)
      	at io.keikai.importer.XlsxImporter.importCellXf(XlsxImporter.java:2073)
      	at io.keikai.importer.XlsxImporter.importCell(XlsxImporter.java:1352)
      	at io.keikai.importer.XlsxImporter.importRow(XlsxImporter.java:1339)
      	at io.keikai.importer.XlsxImporter.imports(XlsxImporter.java:269)
      	... 46 more
      Caused by:java.lang.NullPointerException
      	at io.keikai.util.XlsxJsonHelper.toBool(XlsxJsonHelper.java:62)
      	at io.keikai.importer.XlsxExtractor$XlsxProtectionExtractor.isLocked(XlsxExtractor.java:1135)
      	at io.keikai.importer.XlsxImporter.importCellXf(XlsxImporter.java:2073)
      	at io.keikai.importer.XlsxImporter.importCell(XlsxImporter.java:1352)
      	at io.keikai.importer.XlsxImporter.importRow(XlsxImporter.java:1339)
      	at io.keikai.importer.XlsxImporter.imports(XlsxImporter.java:269)
      	at io.keikai.range.impl.imexp.ExcelImportAdapter.imports(ExcelImportAdapter.java:48)
      	at io.keikai.range.impl.imexp.AbstractImporter.imports(AbstractImporter.java:57)
      	at io.keikai.ui.Spreadsheet.getSBook(Spreadsheet.java:634)
      	at io.keikai.ui.Spreadsheet.getSelectedSSheet(Spreadsheet.java:813)
      	at io.keikai.ui.Spreadsheet.doInvalidate(Spreadsheet.java:2494)
      	at io.keikai.ui.Spreadsheet.invalidate(Spreadsheet.java:2351)
      	at io.keikai.ui.Spreadsheet.setSrc(Spreadsheet.java:853)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      	at java.lang.reflect.Method.invoke(Unknown Source)
      	at org.zkoss.zk.ui.metainfo.Property.assign0(Property.java:332)
      	at org.zkoss.zk.ui.metainfo.Property.assign(Property.java:174)
      	at org.zkoss.zk.ui.metainfo.ComponentInfo.applyProperties(ComponentInfo.java:742)
      	at org.zkoss.zk.ui.impl.AbstractUiFactory.newComponent(AbstractUiFactory.java:146)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:924)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:894)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:781)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:745)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:939)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:894)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:781)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:841)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:799)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:745)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:466)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:374)
      	at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:215)
      	at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:140)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
      	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
      	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
      	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
      	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      	at org.mortbay.jetty.Server.handle(Server.java:326)
      	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
      	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
      	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
      	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
      	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
      

       

       

      Expected Result

      empty protection should be treated as not existing, instead of being imported with a null content

      Debug Information

      importing from Repro.xlsx\xl\styles.xml

      The protection object looks like:

       

      <cellXfs count="2">
          <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyProtection="1">
              <protection />
          </xf>
          <xf numFmtId="0" fontId="1" fillId="0" borderId="1" xfId="1" applyProtection="1">
              <protection/>
          </xf>
      </cellXfs>
      

       

      When importing these styles, XlsxProtectionExtractor / XlsxXfExtractor are initialized with a jsonMap containing {protection: null}, which then triggers the NPE when another method tries to access the content of protection.

      Workaround

      remove the empty <protection/> element from xlsx file.

      Check for null before initializing the extractor with the jsonMap content

       

        1. ImportTest_10965.java
          0.3 kB
          MDuchemin
        2. Repro.xlsx
          9 kB
          MDuchemin

            RaymondChao RaymondChao
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: