Blog

  • 2024
  • 2023
  • 2022
  • 2021
  • 2020
  • 2019
  • 2018
  • 2017
  • 2016
  • 2015
  • 2014
  • 2013
  • 2012




Creating pages automatically in Confluence via the Java API is not exactly a no-event, but not too hard either.

When creating and saving a page we run into a NullPointerException within the PageEditedPayloadTransformer.

[confluence.notifications.impl.NotificationsEventDispatcher] errorOrDebug Error during notification dispatch : null
[INFO] java.lang.NullPointerException
[INFO]   at com.atlassian.confluence.notifications.content.transformer.PageEditedPayloadTransformer.getOriginalId(PageEditedPayloadTransformer.java:20)
[INFO]   at com.atlassian.confluence.notifications.content.transformer.PageEditedPayloadTransformer.getOriginalId(PageEditedPayloadTransformer.java:12)
[INFO]   at com.atlassian.confluence.notifications.content.ContentEditedPayloadTransformer.checkedCreate(ContentEditedPayloadTransformer.java:12)
[INFO]   at com.atlassian.confluence.notifications.PayloadTransformerTemplate.create(PayloadTransformerTemplate.java:38)
[INFO]   at com.atlassian.confluence.notifications.impl.NotificationsEventDispatcher.handleEventInternal(NotificationsEventDispatcher.java:86)
[INFO]   at com.atlassian.confluence.notifications.impl.NotificationsEventDispatcher.handleEvent(NotificationsEventDispatcher.java:58)
[INFO]   at sun.reflect.GeneratedMethodAccessor159.invoke(Unknown Source)
[INFO]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO]   at java.lang.reflect.Method.invoke(Method.java:497)
[INFO]   at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36)
[INFO]   at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1$1.run(AsynchronousAbleEventDispatcher.java:48)
[INFO]   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[INFO]   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[INFO]   at java.lang.Thread.run(Thread.java:745)

There is already an unresolved issue, CONF-37161, which reads:

While trying to render notifications for page edits, PageEditedPayloadTransformer can get NullPointerExceptions while calling getOriginalId. This is because the PageEditedEvent is not required to contain the original page id - it can be null. The code needs to not implicitly cast a Long to a long, since that's causing the null pointer exception in this case.

CONF-37161

In case that you do not need to send notifications, you may use a SaveContext that simply suppresses these.

Indicates that notifications should not be sent out informing users of the changes to this content. 

SaveContext.isSuppressNotifications()

The pre-constructed context SUPPRESS_NOTIFICATIONS is handy for this use case.

final SaveContext saveContext = DefaultSaveContext.SUPPRESS_NOTIFICATIONS;
pageManager.saveContentEntity(page, saveContext);

Saving the page entity with this context will no longer raise the NPE.


Link

Link

Posts