Confluence Servlet module class cast exception

I couldn’t tell, it is mostly lying around and used sparsely (the main function of this plugin is to do background jobs and then export data to other tools for visualization). Meanwhile Confluence is upgraded, java is upgraded, etc., so it might have been either any of the update on the plugin itself or simply Confluence version at some point got incompatible. Tough to say when.

I couldn’t figure it out at first so I left it for a while. Later on, another plugin also broke, so I strapped in the chair for a bit and finally got to fix it.

With ClassLoader errors, I checked the pom dependencies to see how many instances of javax.servlet there are, and surely enough found one culprit:

$ /c/Applications/Atlassian/atlassian-plugin-sdk-8.2.7/apache-maven-3.5.4/bin/mvn dependency:tree
...
[INFO] +- org.apache.velocity:velocity-tools:jar:1.3:compile
[INFO] |  +- commons-digester:commons-digester:jar:1.8:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1:compile
[INFO] |  |  +- logkit:logkit:jar:1.0.1:compile
[INFO] |  |  \- avalon-framework:avalon-framework:jar:4.1.3:compile
[INFO] |  +- javax.servlet:servlet-api:jar:2.3:compile					// AHA, HERE YOU ARE!
[INFO] |  +- oro:oro:jar:2.0.8:compile
[INFO] |  +- sslext:sslext:jar:1.2-0:compile
[INFO] |  +- struts:struts:jar:1.2.9:compile
[INFO] |  \- velocity:velocity:jar:1.4:compile
[INFO] |     \- velocity:velocity-dep:jar:1.4:runtime

More on this bugger later.

Tied’s hint put me on the right path here – I didn’t know before you can just add <dependencyManagement> and have the plugin fetch appropriate versions on the fly (never in years had problem with dependencies so never really bothered, I only need the plugins to work for a specific version at a time since they are not commercial).
I looked into it a bit, tried to understand how it works. Create Confluence Server Ver 8 Plugin - #3 by ShellyNizri has also been a good help along the way.

Now the actual changes that I did to unbork it:

  • Add the dependencyManagement to pom
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.atlassian.confluence</groupId>
                <artifactId>confluence-plugins-platform-pom</artifactId>
                <version>${confluence.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

Good stuff.

  • Replace javax.servlet-api with jakarta:
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet.jsp</groupId>
            <artifactId>jakarta.servlet.jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>
  • Check if confluence already includes velocity tools, it does! So remove this pesky compile scope with a provided one that will now use Confluence’s version:
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-tools</artifactId>
            <scope>provided</scope>
        </dependency>

I also suspect this thing was causing the CL problems, since it was including javax.servlet-api itself. I have to yet test if the Atlassian fork works fine, but that’s for tomorrow. Wouldn’t mind creating my own little util for the few methods that are used in a handful of velocity templates if it comes to it.

  • Next, I found that properties had
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

So I just upped this to 11. (I don’t think it caused any problems though since the plugin pretty much worked fine, but since I read about it not being cool with Confluence 8 and that Java 11 is the way to go, why not.)

Wiped the target directory with clean, re-run mvn dependency:tree and checked that it does not contain any suspicious velocity or servlet dependencies, repackages, installed - and all is good and well now.

In retrospect, I really wonder for how long this might have been there, but my (limited) theory is that this worked in the past and finally gave up with Confluence 8. It just might have been a long time before somebody spotted it since we really don’t use it directly almost at all.

Thanks for the hints guys!

1 Like