Confluence throws NullPointerException when migrating attachments from database to filesystem
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
Problem
You get a NullPointerException error when trying to migrate from using the database to using the file system storage for attachments.
In the logs, you will see the pre-migration tasks start:
INFO [Long running task: Attachment data migration] [persistence.dao.hibernate.AbstractHibernateAttachmentDao] migrate Performing pre-migration tasks.
Followed by this error:
ERROR [Long running task: Attachment data migration] [confluence.util.longrunning.AttachmentMigrationLongRunningTask] runInternal
-- referer: https://wiki.example.com/admin/doeditattachmentstorage.action | url: /admin/doattachmentmigration.action | userName: admin | action: doattachmentmigration
java.lang.NullPointerException
at java.io.File.<init>(File.java:277)
at com.atlassian.confluence.pages.persistence.dao.BootstrapAttachmentLocationResolver.getFileLocation(BootstrapAttachmentLocationResolver.java:19)
at com.atlassian.confluence.pages.persistence.dao.filesystem.FileSystemAttachmentDataDao.prepareForMigrationTo(FileSystemAttachmentDataDao.java:254)
at com.atlassian.confluence.pages.persistence.dao.hibernate.AbstractHibernateAttachmentDao$IntraHibernateAttachmentMigrator.migrate(AbstractHibernateAttachmentDao.java:883)
at com.atlassian.confluence.util.longrunning.AttachmentMigrationLongRunningTask$1.doInTransactionWithoutResult(AttachmentMigrationLongRunningTask.java:72)
at org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128)
at com.atlassian.confluence.util.longrunning.AttachmentMigrationLongRunningTask.runInternal(AttachmentMigrationLongRunningTask.java:66)
at com.atlassian.confluence.util.longrunning.ConfluenceAbstractLongRunningTask.run(ConfluenceAbstractLongRunningTask.java:27)
at com.atlassian.confluence.util.longrunning.ManagedTask.run(ManagedTask.java:58)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Diagnosis
Environment
- Previously you used an older version of Confluence (e.g. 5.4 and earlier) with attachments stored in the database.
- You upgraded at some point to a newer version of Confluence (e.g.: 5.9 or 5.10) and attempted to migrate attachments to the filesystem
Cause
This is caused by a missing parameter in confluence.cfg.xml which defines the attachment storage location:
<property name="attachments.dir">${confluenceHome}/attachments</property>
Resolution
Add the above line to /path/to/confluence-home/confluence.cfg.xml – for example see line 13 below:
<?xml version="1.0" encoding="UTF-8"?> <confluence-configuration> <setupStep>complete</setupStep> <setupType>custom</setupType> <buildNumber>5998</buildNumber> <properties> <property name="admin.ui.allow.daily.backup.custom.location">false</property> <property name="admin.ui.allow.manual.backup.download">false</property> <property name="admin.ui.allow.site.support.email">false</property> <property name="atlassian.license.message">xxxxxxxxxxxxxxxxxxxxxaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</property> <property name="confluence.setup.server.id">XXXX-XXXX-XXXX-XXXX</property> <property name="attachments.dir">${confluenceHome}/attachments</property> <property name="confluence.webapp.context.path"></property> <property name="hibernate.c3p0.acquire_increment">1</property> <property name="hibernate.c3p0.idle_test_period">100</property> <property name="hibernate.c3p0.max_size">30</property> <property name="hibernate.c3p0.max_statements">0</property> <property name="hibernate.c3p0.min_size">0</property> <property name="hibernate.c3p0.timeout">30</property> <property name="hibernate.connection.driver_class">org.postgresql.Driver</property> <property name="hibernate.connection.isolation">2</property> <property name="hibernate.connection.password">Sanitized by Support Utility</property> <property name="hibernate.connection.url">jdbc:postgresql://localhost/wiki</property> <property name="hibernate.connection.username">Sanitized by Support Utility</property> <property name="hibernate.database.lower_non_ascii_supported">true</property> <property name="hibernate.dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property> <property name="hibernate.setup">true</property> <property name="lucene.index.dir">${localHome}/index</property> <property name="webwork.multipart.saveDir">${localHome}/temp</property> </properties> </confluence-configuration>
- Re-run the attachment migration