Attachment Cannot be Cast to AbstractPage error message thrown when attempting to delete a user

XMLWordPrintable

    • Type: Bug
    • Resolution: Cannot Reproduce
    • Priority: Low
    • None
    • Affects Version/s: 6.7.0, 6.12.2
    • Component/s: User - Management
    • None
    • 2
    • Severity 3 - Minor

      Summary

      When attempting to delete a user that has inline comments in attachments an unhandled error is thrown saying that an Attachment type cannot be cast to AbstractPage type.

      Cause
      org.apache.velocity.exception.MethodInvocationException: Invocation of method 'isUserRemovable' in class com.atlassian.confluence.user.actions.RemoveUserAction threw exception java.lang.ClassCastException: com.atlassian.confluence.pages.Attachment cannot be cast to com.atlassian.confluence.pages.AbstractPage at /admin/users/removeuser.vm[line 34, column 23]
          at org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.java:223)
      
      caused by: java.lang.ClassCastException: com.atlassian.confluence.pages.Attachment cannot be cast to com.atlassian.confluence.pages.AbstractPage
          at com.atlassian.confluence.spaces.persistence.dao.hibernate.HibernateSpaceDao.getSpacesContainingCommentsByUser(HibernateSpaceDao.java:180)
      

      Environment

      Confluence 6.12.2 and below

      Steps to Reproduce

      1. Create a local user
      2. Log in with this user
      3. Comment in an attachment in any page (image, pdf, doc, etc)
      4. Log in as admin
      5. Attempt to delete this new local account

      Expected Results

      A warning message saying that this user has content will appear to the administrator and the user will not be deleted.

      Actual Results

      The below exception is thrown in the atlassian-confluence.log file:

      2018-03-07 11:10:04,424 WARN [http-nio-8090-exec-8] [confluence.impl.hibernate.ConfluenceHibernateTransactionManager] doRollback Performing rollback. Transactions:
        ->[null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT (Session #1040722209)
       -- referer: http://quicksilver/confluence/admin/users/viewuser.action?username=bugtest | url: /confluence/admin/users/removeuser.action | traceId: ed747904efbf3285 | userName: admin
      2018-03-07 11:10:04,425 ERROR [http-nio-8090-exec-8] [atlassian.confluence.servlet.ConfluenceServletDispatcher] sendError Could not execute action
       -- referer: http://quicksilver/confluence/admin/users/viewuser.action?username=bugtest | url: /confluence/admin/users/removeuser.action | traceId: ed747904efbf3285 | userName: admin
      org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getUserCommentedSpaces' in  class com.atlassian.confluence.user.actions.RemoveUserAction threw exception java.lang.ClassCastException: com.atlassian.confluence.pages.Attachment cannot be cast to com.atlassian.confluence.pages.AbstractPage at /admin/users/removeuser.vm[line 51, column 31]
        at org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.java:223)
        at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:262)
        at org.apache.velocity.runtime.parser.node.ASTReference.evaluate(ASTReference.java:470)
        at org.apache.velocity.runtime.parser.node.ASTNotNode.evaluate(ASTNotNode.java:63)
        at org.apache.velocity.runtime.parser.node.ASTExpression.evaluate(ASTExpression.java:62)
        at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:85)
        at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
        at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:87)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
        at org.apache.velocity.Template.merge(Template.java:328)
        at org.apache.velocity.Template.merge(Template.java:235)
        at com.opensymphony.webwork.dispatcher.VelocityResult.doExecute(VelocityResult.java:91)
        at com.atlassian.xwork.results.ProfiledVelocityResult.doExecute(ProfiledVelocityResult.java:21)
        at com.atlassian.confluence.setup.webwork.EncodingVelocityResult.doExecute(EncodingVelocityResult.java:43)
      

      Workaround

      The workaround is to delete the comments that this user has. To do that, first we'll grab the user_key of the affected user, then we'll run three queries to delete the entries.
      Please, save a backup copy of your database before running any of the queries below.

      SELECT user_key
      FROM user_mapping
      WHERE username = 'affected_username';
      
      • Replace the affected_username with the proper username that is affected by the bug.
      DELETE FROM BODYCONTENT WHERE CONTENTID IN (SELECT CONTENTID FROM CONTENT WHERE CREATOR='affected_user_key' AND CONTENTTYPE='COMMENT');
      
      DELETE FROM CONTENTPROPERTIES WHERE CONTENTID IN (SELECT CONTENTID FROM CONTENT WHERE CREATOR='affected_user_key' AND CONTENTTYPE='COMMENT');
      
      DELETE FROM CONTENT WHERE CREATOR='affected_user_key' AND CONTENTTYPE='COMMENT';
      

      Make sure to replace the affected_user_key value with the proper user_key.

      Try to delete the user in the UI again after running the queries above and restarting Confluence. You might need to log in with the user and discard any drafts if you still can't delete the user and is sure that the user didn't create any content.

              Assignee:
              Unassigned
              Reporter:
              Eduardo Mallmann (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: