NoSuchMethodError and java method signatures

Well, I'm always learning.
Some times I learn the easy way (by reading about the mistake I'm about to make), but more often I actually make the mistake and end up banging my head on the desk.
This painful learning experience makes sure I don't do the same mistake again.

While working in a Java project I assumed that I could change a method's return type (I made sure the return value was not being used anywhere) and have no impact on other modules (jars/bundles) of the application. After all, both the list of possible exceptions and the return type of a method are not part of its signature.

This is where I made my mistake: I just compiled a new jar and uploaded it to the staging environment. I left all the others untouched.
Then I got a java.lang.NoSuchMethodError.
After some digging I found out that although the signature is the same, the runtime symbol (the changed method) we are replacing is not kept unchanged.

The solution is to either revert the change, or re-compile the other jars that refer to that method and re-upload them.

Binary compatibility is an interesting beast.


Rui Pires

Working as a professional full time remote developer from the Azores since 2011.

Read More