Class file is broken' Scala compiler error

The Stash REST common library provides many nice helper classes for building REST services. You can include it in your Stash plug-in by using the following dependency in your POM file:

Stash REST common library Maven dependency

Recently we’ve made use of some of these helper classes in one of our Scala-based Stash plug-ins (which is now called Bitbucket server, but for a version < 4.0.0 so we stick with Stash here) and soon encountered the following compiler error:

[WARNING] warning: Class org.codehaus.jackson.map.annotate.JsonSerialize not found - continuing with a stub.
[ERROR] warning: Caught: java.lang.NullPointerException while parsing annotations in /Users/michael/.m2/repository/com/atlassian/stash/stash-rest-common/3.6.0/stash-rest-common-3.6.0.jar(com/atlassian/stash/rest/data/RestErrorMessage.class) [ERROR] warning: Caught: java.lang.RuntimeException: bad constant pool index: 0 at pos: 1743 while parsing annotations in /Users/michael/.m2/repository/com/atlassian/stash/stash-rest-common/3.6.0/stash-rest-common-3.6.0.jar(com/atlassian/stash/rest/data/RestErrorMessage.class) [ERROR] error: error while loading RestErrors, class file '/Users/michael/.m2/repository/com/atlassian/stash/stash-rest-common/3.6.0/stash-rest-common-3.6.0.jar(com/atlassian/stash/rest/data/RestErrors.class)' is broken

As you can see, the compiler was not able to find the Jackson annotation JsonSerialize on the classpath which one of the classes from the Stash REST common library is using. This can be because this library was heavily optimized or because other libraries exported this annotation as well and so this library excluded the JAR from its dependencies to avoid conflicts.

While Java is ignoring this issue, the Scala compiler does not and yields a “class file is broken” error. To fix this, you have to make sure that this annotation is present on your classpath. Fortunately, the Atlassian REST common package which is shipped with Stash anyway (note the “provided” Maven scope) includes this annotation, so you can fix this issue by adding the following dependency to your POM file:

Atlassian REST common library Maven dependency

Problem solved.

Comments

comments powered by Disqus