Unable to Create Page from a Template That Uses the Attachments Macro

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

Symptoms

When attempting to create a page from a Confluence Page Template that contains the {attachments} macro and one or more page template variables, Confluence is unable to create the page and an error message is generated after the Insert Variables button is selected.

The error message generated is similar to this:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2010-02-01 12:04:09,274 ERROR [http-8080-11] [atlassian.confluence.servlet.ConfluenceServletDispatcher] sendError Could not execute action -- url: /pages/doenterpagevariables.action | userName: admin | referer: http://localhost:8080/pages/createpage-entervariables.action java.lang.ClassCastException: com.atlassian.confluence.pages.Draft cannot be cast to com.atlassian.confluence.pages.AbstractPage at com.atlassian.confluence.pages.persistence.dao.hibernate.HibernateAbstractPageDao.getAbstractPageById(HibernateAbstractPageDao.java:17) at sun.reflect.GeneratedMethodAccessor449.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy33.getAbstractPageById(Unknown Source) at com.atlassian.confluence.pages.DefaultPageManager.getAbstractPage(DefaultPageManager.java:115) at sun.reflect.GeneratedMethodAccessor448.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) ... ...

Cause

This occurs because the {attachments} macro assumes that it is only ever rendered in the context of a Confluence Page. The macro causes the error when it is rendered in the "Draft" mode required for the user to enter in the page template variable values.

Workaround

A suggested workaround for this problem is to write a user macro that includes the {attachments} macro in pages, but does not include the {attachments} macro in drafts. Information on creating user macros can be found in the Confluence Writing User Macros guide. The page templates can be updated to use this new user macro, instead of using the {attachments} macro directly.

Here is an example of a user macro that would solve this problem in Confluence versions 3.x and below:

1 2 3 4 5 #if ($content.getClass().getName().equals("com.atlassian.confluence.pages.Draft")) *NOTE:* The Confluence \{attachments\} macro will be included here when the page is created. #else {attachments} #end

When creating and saving the macro, make sure that the Output is set to Macro generates wiki markup.

For Confluence versions 4.x and above:

1 2 3 4 5 6 ## @noparams #if ($content.getClass().getName().equals("com.atlassian.confluence.pages.Draft")) *NOTE:* The Confluence \{attachments\} macro will be included here when the page is created. #else <ac:macro ac:name="attachments" /> #end
Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.