Mike Q
Mike Q

Reputation: 23219

Spurious NoSuchMethodError

Been getting a NoSuchMethodError on one of our classes on a simple getter method. The odd thing is that we can debug the code and see the error occur in the debugger (by stepping over the relevant line), however we can also use the IDE (IntelliJ IDEA) to see the method does exist.

Doing xxxx.getYYY() evaluates fine through the IDE expression evaluator. And going xxxx.getClass().getMethods() we can see the getYYY() method in the list. We have tried cleaning out all the built files, IDE output directories, IDE caches, rebooting etc and nothing seems to help.

I would understand a NoSuchMethodError would be happening if we had compiled against something but then a different Jar/class was being found at runtime. But that doesn't explain to me why, at runtime while debugging to the line in question, we can see the method is there, but stepping over the line throws the Exception.

Tried reproducing on another machine but it does not reproduce.

Does anyone have any insight into what could be happening here?

Upvotes: 2

Views: 492

Answers (2)

LearningAboutTech
LearningAboutTech

Reputation: 151

NoSuchMethodError - This mostly occurs at runtime. I came across this error, the reason was incompatible versions of asm and cglib libraries in my classpath.

The asm and cglib libraries are used by many frameworks like hibernate, spring, hadoop for runtime byte code manipulation.

Classloader always refers to the first version of the jar on the classpath.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533472

Most likely you are not running the same versions of code in IntelliJ as what you are editing. I get this problem often with lots of maven projects open at once with different versions in dependencies to what I am editing. IntelliJ can get confused (or I get confused as to which version I am actually running)

Upvotes: 2

Related Questions