I have a piece of code that throws java.lang.NoSuchMethodError on runtime that I could not resolve:
private def saveActivationEvent(event: ActivationEvent) = activationEventService.createIfFirst(event)
Implementations:
case class ActivationEvent extends Event
class ActivationEventService extends AbstractEventService[ActivationEvent]
abstract class AbstractExalateEventService[E <: Event] {
def createIfFirst(event: E)(implicit reader: BSONDocumentReader[E], writer: BSONDocumentWriter[E]): Future[Option[BSONObjectID]] = ...
}
I thought it was happening because of the type erasure... Could someone help me to understand the problem?
As I mention in a comment above, any time you see a NoSuchMethodError
, the first thing you should check is that your compile and runtime dependency versions match. For what it's worth I can't think of a way that type erasure could have anything to do with a NoSuchMethodError
—you may see a ClassCastException
if someone has a bad type test that matches because of erasure, but even in that case the problem isn't really the erasure, it's the fact that someone is trying to work around it (and ignored the compiler's warnings).