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 products 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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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

Always back up your data before making any database modifications. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.

  1. Stop Confluence

  2. ⚠️ Backup Confluence and the database.

  3. Run the following query

    1 2 3 4 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);
  4. Clear the plugin cache

  5. Rebuild the Content Indexes From Scratch

  6. Start Confluence

Updated on April 14, 2025

Still need help?

The Atlassian Community is here for you.