An error occurred while searching for spaces in Space Directory after Importing a Space Backup into Confluence
Platform Notice: Data Center Only - This article only applies to Atlassian apps on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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
The message "An error occurred while searching for spaces." is thrown when accessing the space directory after a space import is run.
Environment
Confluence Server or Data Center
A space was recently imported
Diagnosis
Reviewing <home-directory>/logs/atlassian-confluence.log an error like such will be displayed:
💡Note "spacedirectory/view.action" in the referer shows the space directory is being loaded
atlassian-confluence.log
2020-08-21 13:48:58,780 ERROR [http-nio-6702-exec-1] [common.error.jersey.ThrowableExceptionMapper] toResponse Uncaught exception thrown by REST service: The body of this ContentEntityObject ('') was 'BodyType:XHTML' but was expected to be 'BodyType:WIKI'
-- referer: http://localhost:6702/c702/spacedirectory/view.action | url: /c702/rest/spacedirectory/1/search | traceId: 10fc4d197ff99f11 | userName: admin
java.lang.UnsupportedOperationException: The body of this ContentEntityObject ('') was 'BodyType:XHTML' but was expected to be 'BodyType:WIKI'
at com.atlassian.confluence.core.ContentEntityObject.getBodyContent(ContentEntityObject.java:275)
at com.atlassian.confluence.core.ContentEntityObject.getBodyAsString(ContentEntityObject.java:317)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:84)
at com.atlassian.hibernate.adapter.proxy.JavassistLazyInitializer_ImplementV2Proxy.invoke(JavassistLazyInitializer_ImplementV2Proxy.java:68)
at com.atlassian.confluence.spaces.SpaceDescription_$$_jvsta6_15.getBodyAsString(SpaceDescription_$$_jvsta6_15.java)
at com.atlassian.confluence.plugins.spacedirectory.rest.DefaultSpaceDirectoryEntityBuilder.build(DefaultSpaceDirectoryEntityBuilder.java:84)
at com.atlassian.confluence.plugins.spacedirectory.rest.SpaceDirectoryResource.doSearch(SpaceDirectoryResource.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.atlassian.plugins.rest.common.interceptor.impl.Dis
....Cause
The spacedescription from the imported space has a differing bodytypeid in the bodycontent table than the existing spaces.
When a page has multiple bodytypeid ids in its bodycontent, Confluence is unable to render the page.
Solution
Warning: Backup your database before proceeding.
Before running any SQL in this article, create a full backup of your Jira database. This is a database-level operation with no undo other than restoring from backup. Only proceed if you're comfortable running SQL directly against the Jira database, and test on a staging or cloned environment first, wherever possible.
Stop Confluence
⚠️ Backup Confluence and the database.
Run the following query
UPDATE bodycontent SET bodytypeid = 0 WHERE contentid in (SELECT DISTINCT content.contentid FROM content INNER JOIN bodycontent on content.contentid = bodycontent.contentid where contenttype = 'SPACEDESCRIPTION' and bodytypeid != 0);Start Confluence
Was this helpful?