I'm one of the Bitbucket Server developers. It's not clear how you're registering your event listener from the snippet you posted. It's also not clear how your add-on is packaged, and that's important too.
If you have a component (whether created using @Component
and spring-scanner
or created using a <component/>
tag in atlassian-plugin.xml
), you should never need to explicitly reference EventPublisher.register
or unregister
. Bitbucket Server includes a helper that detects @EventListener
annotations as add-on components are being created/destroyed and automatically handles their registration/unregistration. That means if you use EventPublisher
to manually register your listener instance it gets registered twice, and receives every event twice.
Another possibility, though, is that you're actually ending up with 2 instances of your listener being registered. You can typically "see" this easily in a debugger by putting a breakpoint in an @EventListener
method and looking at System.identityHashCode(this)
(where this
is your listener instance) each time the breakpoint is hit. If you get more than one result from identityHashCode
, it means you have multiple instances. (If you haven't overridden toString()
on your listener you should also be able to use that to determine if you have multiple instances, since the default implementation includes the identity hashcode as hex characters.) I've helped other add-on developers fix issues where they had multiple instances of their listeners; for example, the stash2slack add-on. That thread might be useful to you too.
If you'd like to share some additional details about your add-on, I'd be happy to help investigate further.