Unable to export spaces due to NPE with attachments
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Space export fails with the following error in Confluence.
2021-04-07 15:48:08,596 ERROR [Long running task: Export Space] [confluence.importexport.actions.ExportSpaceLongRunningTask] doInTransactionWithoutResult Error during export
-- url: /spaces/doexportspace.action | traceId: 3a7067bc657ce1f2 | userName: admin | referer: https://confluence.com/spaces/exportspacexml.action?key=FB | action: doexportspace
java.lang.NullPointerException
at com.atlassian.confluence.pages.persistence.dao.filesystem.HierarchicalMultiStreamAttachmentDataFileSystem.getContainerDirectoryForAttachmentVersions(HierarchicalMultiStreamAttachmentDataFileSystem.java:136)
at com.atlassian.confluence.pages.persistence.dao.filesystem.HierarchicalMultiStreamAttachmentDataFileSystem.getAttachmentDataFile(HierarchicalMultiStreamAttachmentDataFileSystem.java:341)
Environment
Confluence installed with user installed apps like ConfiForms - Data Forms & Workflows
Diagnosis
Enable the following DEBUG logging in Confluence to track down the page which have faulty attachments.
com.atlassian.confluence.pages.persistence.dao
com.atlassian.confluence.importexport
com.atlassian.hibernate.extras.XMLDatabinder
Reproducing the issue will show logs like follows,
2021-04-08 13:59:05,868 DEBUG [Long running task: Export Space] [persistence.dao.hibernate.AbstractHibernateAttachmentDao$IntraHibernateAttachmentCopier] copy Copying attachment 'Attachment: File.pdf v.2 (123253720) d789770' and 1 previous versions.
2021-04-08 13:59:05,869 INFO [Long running task: Export Space] [persistence.dao.filesystem.TrackingAttachmentDataFileSystem] send Published a AttachmentDataFileSystemEvent - HierarchicalMultiStreamAttachmentDataFileSystem
2021-04-08 13:59:05,872 ERROR [Long running task: Export Space] [confluence.importexport.actions.ExportSpaceLongRunningTask] doInTransactionWithoutResult Error during export
-- url: /spaces/doexportspace.action | traceId: eec553843dc30929 | userName: d964936 | referer: https://confluence.com/spaces/exportspacexml.action?key=FB | action: doexportspace
java.lang.NullPointerException
So, it is likely that this attachment (File.pdf) is causing issues during export. Try to exclude this page from the export and see if the export is successful.
To find which page this attachment belongs too, use the following SQL,
select pageid from content where title = 'File.pdf';
Then navigate to that page using the following URL,
Update pageid at the end<Confluence Base URL>/pages/viewpage.action?pageId=
Now that we know which page this is, we can exclude this page from Export
Space Export > Custom Export > Uncheck the above page
Cause
Attachments used by the apps are not stored as Confluence attachments. Navigating to page options > Attachment will results in zero attachments.