Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing return type of method gives java.lang.NoSuchMethodError

Tags:

java

I changed the return type of one method in an interface in a library. Previously it was void and I modified it to return an object. I did not change the code in my module as I did not want to do anything with the returned object(it was for a different module) I compiled my module with the new library jar and ran unit tests which ran fine but when I pushed the jar along with the library jar to production and ran the module, i get java.lang.NoSuchMethodError for the method I changed on the interface. I modified the interface as well as the implementation, both are in the library jar and I use spring annotations to inject the implementation object in my module. What is the possible cause of this problem?

like image 807
Arvind Avatar asked Jul 15 '09 21:07

Arvind


2 Answers

In the Java bytecode the return type of a method is part of the method signature, and it differentiates between two methods with the same name and same parameters (this is something that you cannot do in the Java language). So your code which calls this method somehow wasn't recompiled and it still tries to call the method which returns void.

like image 134
Gábor Hargitai Avatar answered Sep 28 '22 08:09

Gábor Hargitai


It sounds like you haven't recompiled everything, or haven't pushed all the recompiled jar files to prod.

Additionally, you didn't specify whether you restarted the server. If you've got some sort of "hot restart" going on, you'll have to have configured all the classloaders very carefully to get it right. If you can restart the container completely, that may help.

like image 21
Jon Skeet Avatar answered Sep 28 '22 08:09

Jon Skeet