Spring, Thymeleaf and Java 8

As a software developer, do you ever get so excited by new technologies or features that you're unable to resist the urge to use them in a project? I'm sure I'm not the only one who has this problem.

In fact, it even happened to me this week. While developing a small new project to teach people some new features of Java 8 in a Koan-styled tutorial. I got so excited by all of these new features, I just had to use them in a web application I've been developing for some time now.

A little background on the web aplication

There isn't much to know on the application itself. Basically, it's a Maven-build project, in multiple layers. The technologies used - which are important for this post - are Spring 4, Thymeleaf and Hibernate.

The Stacktrace

While booting, the following stacktrace presented itself.

Caused by: org.hibernate.jpa.boot.archive.spi.ArchiveException: Could not build ClassFile at org.hibernate.jpa.boot.scan.spi.ClassFileArchiveEntryHandler.toClassFile(ClassFileArchiveEntryHandler.java:88) ~[ClassFileArchiveEntryHandler.class:4.3.4.Final] at ...

It didn't look good. Apparently, there was a problem with Hibernate as it wasn't able to construct a classfile. Of course, the main changes that were made were some operations on collections, which I changed to be operations on the new Stream API.

Next up, I had to find out why it couldn't build the classfile. Hibernate version 4.3.4.Final was fully compatible with Java 8, so why did it fail? I had to dig a little deeper..

By glancing at the stacktrace, I knew I had to look at ClassFileArchiveEntryHandler. I put a breakpoint at the point where it threw the exception and quickly found the next part of a stacktrace:

java.io.IOException: invalid constant type: 18 at 14

Throwing this exception message in google quickly showed me that Javassist was having issues with my class file. But according to hibernate's documentation, it was already using the newest version (3.18.1-GA), so why didn't it build my class?

The beauty of IntelliJ IDEA

In comes IntelliJ! I remembered IntelliJ has a nice feature to check your Maven pom for all of its dependencies, and plot them in a nice Diagram.

Searching for Javassist, the problem quickly became crystal clear.
Intellij Maven

Apparently, the newest version of Thymeleaf was still using an older version of Javassist. This older version of Thymeleaf got loaded and wasn't able to do its byte manipulation when it comes to the new features of Java 8.


Until Thymeleaf decides to use the newest version of Javassist, we have to exclude it as a dependency.