Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-58212

Accessing the Drafts page within a user profile throws a NullPointerException on getResumableDraftsBySpace

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Low
    • None
    • 6.6.12, 6.13.3, 6.15.9
    • User - Profile
    • None

    Description

      Issue Summary

      When a Confluence user access the Drafts page within their profile, they receive a System Error in the UI instead of a table with all the unpublished drafts.

      Environment

      • This issue was validated on Confluence Server 6.6.12 with PostgreSQL.
      • It was validated with both Collaborative Editing enabled and disabled.
      • It was also reported with MySQL database – so it is not DB engine specific.
      • This issue was validated on Confluence Server 6.13.3 with PostgreSQL and CE enabled.

      Steps to Reproduce

      1. Install a Confluence vanilla instance.
      2. As a Confluence user, go to any Space and click on the Create blank page button.
      3. Give the page a title, add any content to the page and click on the Close button.
        • When prompted to close the editor, click on the Keep draft button.
      4. In the Confluence database, get the CONTENTID of the newly created draft and run the following SQL query.
        update CONTENT set CREATIONDATE = NULL, LASTMODDATE = NULL WHERE CONTENTID = <draft ID>
        
        • This will make both the CREATIONDATE and the LASTMODDATE equal to NULL.
      5. As a Confluence administrator, go to Cog icon > General configuration > Cache Management.
      6. Search for Content Objects cache and click on the Flush button related to it.
      7. As the Confluence user who created the draft, go to Profile > Drafts.
        • Or access <Confluence Base URL>/users/viewmydrafts.action

      A very similar stack trace can be reproduced if one of the spaces associated with the drafts has an empty title. To reproduce this:

      update SPACES set SPACENAME = NULL WHERE SPACEID = <space ID>;
      

      Expected Results

      The page with unpublished drafts touched by the current user is shown.

      Actual Results

      A System Error is shown in the UI with a stack trace similar to the one below.

      For issues related to the dates, the NPE will be thrown by the class java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469)

      Cause

      org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getResumableDraftsBySpace' in class com.atlassian.confluence.user.actions.ViewMyDraftsAction threw exception java.lang.NullPointerException at /users/viewmydrafts.vm[line 123, column 30]
      at org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.java:223)

      caused by: java.lang.NullPointerException
      at java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469)

      Stack Trace:[hide]
      org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getResumableDraftsBySpace' in  class com.atlassian.confluence.user.actions.ViewMyDraftsAction threw exception java.lang.NullPointerException at /users/viewmydrafts.vm[line 123, column 30]
      	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.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.ASTBlock.render(ASTBlock.java:72)
      	at com.atlassian.confluence.setup.velocity.ApplyDecoratorDirective.getRenderedTagBody(ApplyDecoratorDirective.java:181)
      	at com.atlassian.confluence.setup.velocity.ApplyDecoratorDirective.render(ApplyDecoratorDirective.java:155)
      	at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:175)
      	at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
      	at org.apache.velocity.Template.merge(Template.java:328)
      (...)
      	at java.lang.Thread.run(Thread.java:748)
      Caused by: java.lang.NullPointerException
      	at java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469)
      	at java.util.Collections$ReverseComparator2.compare(Collections.java:5178)
      	at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
      	at java.util.TimSort.sort(TimSort.java:220)
      	at java.util.Arrays.sort(Arrays.java:1512)
      	at java.util.ArrayList.sort(ArrayList.java:1462)
      	at java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:387)
      	at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
      	at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
      	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
      	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
      	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
      	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
      	at com.atlassian.confluence.user.actions.ViewMyDraftsAction.filterAndGroupDrafts(ViewMyDraftsAction.java:107)
      	at com.atlassian.confluence.user.actions.ViewMyDraftsAction.getResumableDraftsBySpace(ViewMyDraftsAction.java:88)
      	at sun.reflect.GeneratedMethodAccessor1242.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.apache.velocity.runtime.parser.node.PropertyExecutor.execute(PropertyExecutor.java:142)
      	at org.apache.velocity.util.introspection.UberspectImpl$VelGetterImpl.invoke(UberspectImpl.java:529)
      	at org.apache.velocity.runtime.parser.node.ASTIdentifier.execute(ASTIdentifier.java:198)
      	... 379 more
      

      For issues related to the space name, the stack trace is almost identical to what is seen above, but the NPE comes from at java.lang.String$CaseInsensitiveComparator.compare(String.java:1192)

      Notes

      There's still no reference on how an user created draft doesn't have both the CREATIONDATE and LASTMODDATE. This is also true for space names being null.
      A bug report should be added here when it is found.

      Since both workarounds require direct modification in the database, please make sure you have a recent backup to perform a rollback if necessary.
      Make sure you only run the steps below if you are certain you are affected by this bug.

      Workaround 1 - Fixing null dates

      Execute this if the NPE comes from java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469)

      The known workaround is to manually modify the CREATIONDATE of the affected drafts directly in the database.

      The following SQL query will show you the drafts associated with a specific user, but with CREATIONDATE and LASTMODDATE equal to NULL.
      Make sure you change CHANGE_THE_USERNAME to an actual username.

      Tested for PostgreSQL
      select c.*
      from CONTENT c
      join USER_MAPPING um on c.CREATOR=um.USER_KEY
      where (c.CONTENT_STATUS='draft'
      or c.CONTENTTYPE='DRAFT')
      and (c.CREATIONDATE is NULL and c.LASTMODDATE is NULL)
      and um.USERNAME='CHANGE_THE_USERNAME'
      ;
      

      The following query will update the above records with a CREATIONDATE from another record randomly selected.
      Make sure you change CHANGE_THE_USERNAME to an actual username.

      Tested for PostgreSQL
      update CONTENT set CREATIONDATE = (
      select c.CREATIONDATE
      from CONTENT c
      join USER_MAPPING um on c.CREATOR=um.USER_KEY
      where (c.CONTENT_STATUS='draft'
      or c.CONTENTTYPE='DRAFT')
      and c.CREATIONDATE is not NULL
      limit 1
      )
      where CONTENTID in (
      select c.CONTENTID
      from CONTENT c
      join USER_MAPPING um on c.CREATOR=um.USER_KEY
      where (c.CONTENT_STATUS='draft'
      or c.CONTENTTYPE='DRAFT')
      and (c.CREATIONDATE is NULL and c.LASTMODDATE is NULL)
      and um.USERNAME='CHANGE_THE_USERNAME'
      )
      ;
      

      Workaround 2 - Fixing null space names

      Execute this if the NPE comes from at java.lang.String$CaseInsensitiveComparator.compare(String.java:1192)

      1. Identify if there are any spaces related to the user drafts with NULL names:
        select * from spaces 
        where spaceid in (
        select c.spaceid
        from CONTENT c
        join USER_MAPPING um on c.CREATOR=um.USER_KEY
        where (c.CONTENT_STATUS='draft'
            or c.CONTENTTYPE='DRAFT')
        and um.USERNAME='CHANGE_THE_USERNAME'
        and c.spaceid is not null
        )
        and spacename is null
        ;
        
      2. If any space is returned, take note of the ID and run the following query:
        update SPACES set SPACENAME = 'SPACE-NAME' where SPACEID = <space-id>;
        

      After modifying the database for any of the workarounds, make sure to flush the affected cache or restart Confluence:

      1. As a Confluence administrator, go to Cog icon > General configuration > Cache Management.
      2. Search for Content Objects cache and click on the Flush button related to it.

      Attachments

        1. drafts_img001.png
          drafts_img001.png
          384 kB
        2. system_error_img001.png
          system_error_img001.png
          508 kB

        Issue Links

          Activity

            People

              Unassigned Unassigned
              tmasutti Thiago Masutti
              Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated: