Changing the type of the returned method gives java.lang.NoSuchMethodError

I changed the return type of one method in the interface in the library. It used to be invalid and I changed it to return an object. I did not change the code in my module, since I did not want to do anything with the returned object (it was for another module) I compiled my module with the new jar library and performed unit tests that performed normally, but when I pushed the jar along with the library jar to release and run the module, I get java.lang.NoSuchMethodError for the method that I changed on the interface. I changed the interface as well as the implementation, both are in the bank of the library, and I use spring annotations to embed the implementation object in my module. What is the possible cause of this problem?

+3
source share
5 answers

It looks like you didn’t recompile all or dragged all the recompiled jar files into prod.

In addition, you did not indicate whether you restarted the server. If you have some kind of "hot restart", you need to carefully configure all the class loaders so that everything is correct. If you can completely reload the container, this may help.

+6
source

In Java bytecode, the return type of the method is part of the method signature, and it distinguishes between two methods with the same names and the same parameters (this is something you cannot do in Java). Thus, your code that calls this method has not been recompiled in some way and is still trying to call the method that returns void.

+5

, , -?

0

( QA), - . ( , , ).

, (, , ), - , . - , JVM .

0

voidnot a subtype of any other type. Therefore, if you change the interface to return not void, then the implementation classes that still return voidwill no longer be compatible with this method.

0
source

Source: https://habr.com/ru/post/1712722/


All Articles