how to fix a ClassCastException in a Stash Plugin

misleading signs
misleading signs
ClassCastException in stash user interface
error message in stash user interface caused by ClassCastException

Have you ever run into ClassCastException while coding a Stash plugin?

I did several times enjoying the error widget on the right. There were several approaches to fix this including digging deep into the maven dependency tree and comparing dependencies and versions.

....
[INFO] [talledLocalContainer] java.lang.ClassCastException: 
 info.lotharschulz.stash.MyCheck cannot be cast to com.atlassian.stash.scm.pull.MergeRequestCheck
[INFO] [talledLocalContainer] at com.atlassian.stash.scm.pull.MergeRequestCheckModuleDescriptor.
 getModule(MergeRequestCheckModuleDescriptor.java:24) ~[stash-spi-3.3.0.jar:na]
[INFO] [talledLocalContainer] at com.atlassian.stash.internal.pull.DefaultMergeRequestCheckService.
 check(DefaultMergeRequestCheckService.java:43) ~[stash-service-impl-3.3.0.jar:na]
....

Finally, the fix was to make sure the class doing the check (MyCheck in my sample) follows 2 rules:

  1. implements com.atlassian.stash.scm.pull.MergeRequestCheck
  2. is referenced in atlassian-plugin.xml within a merge-ckeck xml tag using the class property

(Unfortunately I used other tags like component initially.)

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
<plugin-info>
<description>${project.description}</description> ...
</plugin-info> ...
<merge-check key="MyCheck" class="info.lotharschulz.stash.MyCheck" />
</atlassian-plugin>

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.