Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-6593

Deleting documents with attachments that have no versioning returning NullPointerException

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 3.1 M2, 3.0.1
    • 3.0
    • Actions, Storage
    • None
    • attachments, no versioning, deleting, nullpointerexception
    • Unknown

    Description

      I have a wiki setup using the file system storage for attachments with versioning disabled. When I attempt to delete a page with attachments, it returns a NullPointerException. Not entirely sure if the file system storage has anything to do with it, but currently the only changed made to the xwiki.cfg file are having the applicable values set to "file" for file system storage, and the following:

      xwiki.store.attachment.versioning.hint=void 
      xwiki.store.attachment.versioning=0
      

      As I attempt to delete a page with attachments, I get so far as confirming the deletion, then this error shows:

      Detailed information:
      
          Error number 0 in 11: Uncaught exception
      Wrapped Exception: null
      com.xpn.xwiki.XWikiException: Error number 0 in 11: Uncaught exception
      Wrapped Exception: null
      	at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:240)
      	at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:117)
      	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
      	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
      	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
      	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
      	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$CachedChain.doFilter(ServletHandler.java:1166)
      	at com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:129)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.xwiki.wysiwyg.server.filter.ConversionFilter.doFilter(ConversionFilter.java:152)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at com.xpn.xwiki.plugin.webdav.XWikiDavFilter.doFilter(XWikiDavFilter.java:68)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.xwiki.container.servlet.filters.internal.SavedRequestRestorerFilter.doFilter(SavedRequestRestorerFilter.java:218)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.xwiki.container.servlet.filters.internal.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:112)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
      	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:765)
      	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
      	at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
      	at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
      	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:536)
      	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:915)
      	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
      	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
      	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)
      	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
      	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
      
      
      Wrapped Exception:
      
      java.lang.NullPointerException
      	at com.xpn.xwiki.doc.XWikiAttachment.toStringXML(XWikiAttachment.java:333)
      	at com.xpn.xwiki.store.VoidAttachmentVersioningStore$VoidAttachmentArchive.getArchive(VoidAttachmentVersioningStore.java:143)
      	at com.xpn.xwiki.doc.XWikiAttachmentArchive.getArchive(XWikiAttachmentArchive.java:126)
      	at com.xpn.xwiki.doc.XWikiAttachment.toXML(XWikiAttachment.java:422)
      	at com.xpn.xwiki.doc.XWikiDocument.toXML(XWikiDocument.java:4024)
      	at com.xpn.xwiki.doc.XWikiDocument.toXML(XWikiDocument.java:4102)
      	at com.xpn.xwiki.doc.XWikiDocument.toXML(XWikiDocument.java:3851)
      	at com.xpn.xwiki.doc.XWikiDocument.toFullXML(XWikiDocument.java:3769)
      	at com.xpn.xwiki.doc.XWikiDeletedDocument.setDocument(XWikiDeletedDocument.java:193)
      	at com.xpn.xwiki.doc.XWikiDeletedDocument.<init>(XWikiDeletedDocument.java:89)
      	at com.xpn.xwiki.store.XWikiHibernateRecycleBinStore.saveToRecycleBin(XWikiHibernateRecycleBinStore.java:68)
      	at com.xpn.xwiki.XWiki.deleteDocument(XWiki.java:4319)
      	at com.xpn.xwiki.XWiki.deleteDocument(XWiki.java:4299)
      	at com.xpn.xwiki.XWiki.deleteAllDocuments(XWiki.java:6228)
      	at com.xpn.xwiki.XWiki.deleteAllDocuments(XWiki.java:6217)
      	at com.xpn.xwiki.web.DeleteAction.action(DeleteAction.java:94)
      	at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:215)
      	at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:117)
      	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
      	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
      	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
      	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
      	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$CachedChain.doFilter(ServletHandler.java:1166)
      	at com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:129)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.xwiki.wysiwyg.server.filter.ConversionFilter.doFilter(ConversionFilter.java:152)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at com.xpn.xwiki.plugin.webdav.XWikiDavFilter.doFilter(XWikiDavFilter.java:68)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.xwiki.container.servlet.filters.internal.SavedRequestRestorerFilter.doFilter(SavedRequestRestorerFilter.java:218)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.xwiki.container.servlet.filters.internal.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:112)
      	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
      	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:765)
      	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
      	at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
      	at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
      	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:536)
      	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:915)
      	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)
      	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
      	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)
      	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
      	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
      

      I looked into the source code in the repository, tracing back through the different classes leading to the NullPointerException, and realized that the XWikiAttachmentArchive.getArchive() function is making a call to another getArchive function passing a null object as the parameter.

      XWikiAttachmentArchive.java: Lines 124-127

      public byte[] getArchive() throws XWikiException
      {
      return getArchive(null);
      }

      This happens to be the getArchive(XWikiContext context) function in the VoidAttachmentVersioningStore class, which then calls the toStringXML function from a XWikiAttachment object, passing the null XWikiContext object as a parameter.

      VoidAttachmentVersioningStore.java: Lines 141-147

      public byte[] getArchive(XWikiContext context) throws XWikiException
      {
      String sdata = getAttachment().toStringXML(true, false, context);
      Object[] lines = ToString.stringToArray(sdata);
      Archive archive = new Archive(lines, getAttachment().getFilename(), getAttachment().getVersion());
      return archive.toByteArray();
      }

      Finally, the toStringXML() function attempts to get the encoding from the wiki of the null XWikiContext object, which I believe causes the exception.

      XWikiAttachment.java: Lines 325-345

      public String toStringXML(boolean bWithAttachmentContent, boolean bWithVersions, XWikiContext context)
      throws XWikiException
      {
      // This is very bad. baos holds the entire attachment on the heap, then it makes a copy when toByteArray
      // is called, then String forces us to make a copy when we construct a new String.
      // Unfortunately this can't be fixed because jrcs demands the content as a String.
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      try {
      XMLWriter wr = new XMLWriter(baos, new OutputFormat("", true, context.getWiki().getEncoding()));
      Document doc = new DOMDocument();
      wr.writeDocumentStart(doc);
      toXML(wr, bWithAttachmentContent, bWithVersions, context);
      wr.writeDocumentEnd(doc);
      byte[] array = baos.toByteArray();
      baos = null;
      return new String(array, context.getWiki().getEncoding());
      } catch (IOException e)

      Unknown macro: { e.printStackTrace(); return ""; }

      }

      Attachments

        Issue Links

          Activity

            People

              sdumitriu Sergiu Dumitriu
              gibbind Devin Gibbins
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: