Fetching page history through REST API throws a NullPointerException at HistoryBuilder.createdDate
This article only applies to Atlassian's server products. Learn more about the differences between cloud and server.
Fetching pages through the REST API and expanding its history (e.g. history.lastupdated) results in a 500 HTTP code and the following error on the atlassian-conlfuence.log file:
[rest.api.model.ExceptionConverter] convertServiceException No status code found for exception, converting to internal server error : -- url: /rest/api/content/<ID>/child/page | traceId: xxxxx | userName: admin java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210) at com.atlassian.confluence.api.model.content.History$HistoryBuilder.createdDate(History.java:231)
Run the following query on the database to check for NULL values:
SELECT * from content where creationdate is NULL and content_status = 'current' and (contenttype = 'PAGE' or contenttype = 'BLOGPOST' or contenttype = 'ATTACHMENT');
If the query above returns any results, this is the cause of the problem. It is expected that all published versions of a given content should have valid dates in this column. If not, the NPE is returned when fetching its history.
Notice that it is expected to have NULL values for that column if the content_status is DRAFT or DELETED. However, if the content_status is CURRENT, that should not happen.
Run the following query to set valid dates for those entries:
UPDATE content SET creationdate ='2018-01-01 01:01:01.001', lastmoddate = '2018-01-01 01:01:01.001' where creationdate is NULL and content_status = 'current' and (contenttype = 'PAGE' or contenttype = 'BLOGPOST');
Ensure that you have stopped the application and taken a database backup before executing this query.
It is not yet known why this situation may happen. On most of the case where this has been seen, the pages affected were created in an unusual way (not from the UI). Below are the most common causes:
- Pages/spaces imported from other wiki tools
- Pages created using scripts or plugins
- Any other type of content migration