How to fix IncompatibleClassChangeError for your Groovy projects running on JDK7
Shortly after JDK7 was released people started complaining on Geb's user mailing list about problems with running Geb on JDK7. The stacktrace contained a line simillar to this one:
Caused by: java.lang.IncompatibleClassChangeError: the number of constructors during runtime and compile time for java.lang.RuntimeException do not match. Expected 4 but got 5
Luke Daley has found out that it is due to the fact that Groovy inspects the number of constructors on classes during compilation and checks if it is still the same during runtime. JDK7 has added a fifth constructor to Exception class so if you compiled your Groovy code that contains any exceptions written in Groovy with JDK6 and you tried to run it with JDK7 you would get a
There is a simple solution to that issue - all you have to do is rewrite your exceptions from Groovy to Java, which will soon remind you how cool Groovy is and how bloated Java code seems to be after not writing any of it for a while.
Just to clarify it's not me who came up with that idea - all credit goes to Luke. I just wanted to write about it because after we fixed it in Geb the issue stroke again... Luke compiled the latest version of Groovy Remote Control with JDK7 and I used it as a dependency in a JDK6 based project. The good thing is that I knew what was going on straightaway and simply rewrote the exception classes in Groovy Remote Control and the next release of the library will be compatible with both JDK6 and JDK7. Also other people hitting the issue might find this post helpful...