commentService.addComment throws NullPointerException during OnPullRequestRescoped, when a pull request is updated

When a pull request is opened, I have this code that adds a comment to the pull request.

@Inject
public OpenPullRequestEventListener(final CommentService commentService)
{
    this.commentService = commentService;
}
  
@EventListener
public void OnPullRequestOpen(PullRequestOpenedEvent pullRequestOpenedEvent)
{
    PullRequest pullRequest = pullRequestOpenedEvent.getPullRequest();

    AddCommentRequest addCommentRequest = new AddCommentRequest.Builder(pullRequest, "Pull request opened.").build();
    this.commentService.addComment(addCommentRequest);
}

This works. A comment gets added when the pull request is opened.
image

When I modify a file on the branch I am pulling into master, I get java.lang.NullPointerException: author

[INFO] 2022-10-13 12:32:23,614 ERROR [AtlassianEvent::thread-13]  c.a.s.i.e.AsyncBatchingInvokersTransformer There was an exception thrown trying to dispatch event 'com.atlassian.bitbucket.event.pull.PullRequestRescopedEvent[source=com.atlassian.stash.internal.pull.DefaultPullRequestService@2e9ed82e]' for the invoker 'SingleParameterMethodListenerInvoker{method=public void com.openlink.bitbucket.plugin.PullRequest.PullRequestUpdateEventListener.OnPullRequestRescoped(com.atlassian.bitbucket.event.pull.PullRequestRescopedEvent), listener=com.openlink.bitbucket.plugin.PullRequest.PullRequestUpdateEventListener@7ebd871d} (monitored)'
[INFO] java.lang.RuntimeException: author. Listener: com.openlink.bitbucket.plugin.PullRequest.PullRequestUpdateEventListener event: com.atlassian.bitbucket.event.pull.PullRequestRescopedEvent
[INFO]  at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:57)
[INFO]  at com.atlassian.diagnostics.internal.platform.event.EventSystemMonitor.invokeMonitored(EventSystemMonitor.java:109)
[INFO]  at com.atlassian.diagnostics.internal.platform.event.MonitoredListenerInvoker.invoke(MonitoredListenerInvoker.java:38)
[INFO]  at com.atlassian.stash.internal.event.AsyncBatchingInvokersTransformer$AsyncInvokerBatch.invoke(AsyncBatchingInvokersTransformer.java:111)
[INFO]  at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.lambda$null$0(AsynchronousAbleEventDispatcher.java:37)
[INFO]  at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:34)
[INFO]  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[INFO]  at com.atlassian.stash.internal.event.EventThreadFactory.lambda$createThread$0(EventThreadFactory.java:35)
[INFO]  at java.lang.Thread.run(Thread.java:748)
[INFO]  ... 1 frame trimmed
[INFO] Caused by: java.lang.NullPointerException: author
[INFO]  at java.util.Objects.requireNonNull(Objects.java:228)
[INFO]  at com.atlassian.stash.internal.comment.InternalComment$Builder.author(InternalComment.java:431)
[INFO]  at com.atlassian.stash.internal.comment.DefaultCommentService.createComment(DefaultCommentService.java:739)
[INFO]  at com.atlassian.stash.internal.comment.DefaultCommentService.createComment(DefaultCommentService.java:729)
[INFO]  at com.atlassian.stash.internal.comment.DefaultCommentService.addComment(DefaultCommentService.java:126)
[INFO]  at com.atlassian.stash.internal.comment.DefaultCommentService.addComment(DefaultCommentService.java:63)
[INFO]  at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26)
[INFO]  at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56)
[INFO]  at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60)
[INFO]  at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
[INFO]  at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
[INFO]  at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
[INFO]  at com.openlink.bitbucket.plugin.PullRequest.PullRequestUpdateEventListener.OnPullRequestRescoped(PullRequestUpdateEventListener.java:48)
[INFO]  at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:42)
[INFO]  ... 9 common frames omitted

Here’s the code for that event:

@Inject
public PullRequestUpdateEventListener(final CommentService commentService)
{
    this.commentService = commentService;
}

@EventListener
public void OnPullRequestRescoped(PullRequestRescopedEvent pullRequestRescopedEvent)
{
    PullRequest pullRequest = pullRequestRescopedEvent.getPullRequest();

    // Quit if the 'from' branch was not updated. This also gets called if the 'to' branch is updated.
    if (! pullRequestRescopedEvent.isFromHashUpdated()) return;

    PullRequestParticipant pullRequestParticipant = pullRequest.getAuthor();

    AddCommentRequest addCommentRequest = new AddCommentRequest.Builder(pullRequest, "Pull request update.").build();
    this.commentService.addComment(addCommentRequest);
}

The pull request is updated with the code change and the comment message but there is no comment added saying “Pull request update.”
image

When I break at AddCommentRequest, pullRequestParticipant is the author of the pull request so I don’t know where NullPointerException: author is coming from.

Am I doing something wrong? Thanks.