I want to make changes to Bitbucket Server Repository Hook for Mirroring (https://github.com/ef-labs/stash-hook-mirror), then remove original and install the updated version.
However, after making such change, Bitbucket starts giving java.lang.ClassCastException
errors with a stacktrace like this:
java.lang.ClassCastException: com.englishtown.bitbucket.hook.MirrorRequest cannot be cast to com.englishtown.bitbucket.hook.MirrorRequest
at com.atlassian.stash.internal.concurrent.HazelcastBucketedExecutor.schedule(HazelcastBucketedExecutor.java:63)
at com.atlassian.stash.internal.concurrent.DelegatingInternalBucketedExecutor.schedule(DelegatingInternalBucketedExecutor.java:24)
at com.englishtown.bitbucket.hook.MirrorRepositoryHook.lambda$schedulePushes$0(MirrorRepositoryHook.java:177)
at java.util.ArrayList.forEach(ArrayList.java:1259)
at com.englishtown.bitbucket.hook.MirrorRepositoryHook.schedulePushes(MirrorRepositoryHook.java:177)
at com.englishtown.bitbucket.hook.MirrorRepositoryHook.validate(MirrorRepositoryHook.java:138)
at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService.validateSettings(DefaultRepositoryHookService.java:896)
at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService.lambda$enable$0(DefaultRepositoryHookService.java:203)
at java.util.Optional.ifPresent(Optional.java:159)
Seems that BitBucket caches data from the plugin and does not purge it after plugin removal. This is a common problem with it - see those tickets: https://github.com/ef-labs/stash-hook-mirror/issues/84 or https://github.com/ef-labs/stash-hook-mirror/issues/83
Suggested workaround there is to restart BitBucket instance, and it works.
Another workaround that seems to work is renaming classes and files to include a version as suffix: like MirrorRepositoryHook.java
to MirrorRepositoryHookV331.java
.
Is there more elegant solution?