A HTTP 500 error is thrown after trying to access Space Tools -> Content Tools in the browser.
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles 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
After an upgrade to Confluence Server or Data Center v7.19.18 (or newer), whenever the SPACE TOOLS → CONTENT TOOLS option is selected for a space (/pages/templates2/listpagetemplates.action?key=<spacekey>), there is an HTTP 500 error thrown in the browser.
Environment
Confluence Server or Data Center 7.19.18 or newer.
Diagnosis
By default, all HTTP 500 errors are logged in the <confluence-home>/logs/atlassian-log.log files. Upon inspecting the log files after the error is thrown, you will see the following stack (among other decorator type errors):
--------------------------
Parameters
--------------------------
key : TEST
src : spacetools
caused by: java.lang.RuntimeException: javax.servlet.ServletException: java.lang.RuntimeException: Error rendering template for decorator space
at com.opensymphony.sitemesh.webapp.decorator.BaseWebAppDecorator.render(BaseWebAppDecorator.java:37)
caused by: javax.servlet.ServletException: java.lang.RuntimeException: Error rendering template for decorator space
at com.atlassian.confluence.util.profiling.ConfluenceSitemeshDecorator$ErrorSendingErrorHandlingStrategy.handleException(ConfluenceSitemeshDecorator.java:279)
caused by: java.lang.RuntimeException: Error rendering template for decorator space
at com.atlassian.confluence.setup.velocity.ApplyDecoratorDirective.render(ApplyDecoratorDirective.java:162)
caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getDisplayableLabel' in class com.atlassian.confluence.impl.plugin.web.readonly.ReadOnlyWebLabel threw exception java.lang.NullPointerException at /templates/link-browser-web-items.vm[line 5, column 33]
at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:342)
caused by: java.lang.NullPointerException
at java.base/java.util.HashMap.putMapEntries(HashMap.java:497)
Cause
In Confluence, we use decorator engines to generate the UI elements and layouts on a space and page level. This allows customization of these elements through custom layouts and templates that a space administrator can modify.
When navigating to SPACE TOOLS → CONTENT TOOLS in your browser, the default landing page for this endpoint is SPACE TOOLS → CONTENT TOOLS → TEMPLATES. This page takes you to the templates at the space and global level, however, in this scenario, there aren't any space or global templates defined (it's default) so we know the issue isn't with templates.
When the SPACE TOOLS → CONTENT TOOLS → TEMPLATES page loads, it also loads the customized layout for that space, which can be found on SPACE TOOLS → LOOK AND FEEL → LAYOUT → CONTENT LAYOUT → SPACE LAYOUT and this is where we find our issue.
Under SPACE LAYOUT, you have a defined layout for that space and if it's customized, under the 'Operator' column you'll see the options to EDIT, RESET DEFAULT or VIEW DEFAULT. If it's set to default it'll state that it's <default>.
Solution
The issue lies with the customized layout code which is missing a portion of code found in the default layout code.
To check, while on the affected space, navigate to SPACE TOOLS → LOOK AND FEEL → LAYOUT:
- Find SPACE LAYOUT under CONTENT LAYOUT
- Click the VIEW DEFAULT operator for SPACE LAYOUT, copy this code into a text editor.
- Click the EDIT operator next and copy this code into a text editor.
- Compare the two, making sure that all of the default layout code also exists in the custom layout code.
For this particular scenario, the customized layout code was missing specific context (webInterfaceContext) code found in the default layout, which caused a NullPointerException (NPE) whenever the hashmap was trying to find the context during loading of the page (in this case, since the context is missing, the application changes the context to default and this is where the null pointer exists). The following code needs to be set after line 58 in the customized layout code (click EDIT for the space layout):
#if (!$webInterfaceContext)
#set ($webInterfaceContext = $action.webInterfaceContext)
#end
If you have any issues adding this code, copy your customized layout code to a text editor and reset the space layout to DEFAULT. Once it's working again, work to reintroduce your customized changes to a new layout, one at a time, and check the SPACE TOOLS → CONTENT TOOLS → TEMPLATES again each time to see where it breaks and adjust accordingly.