KarelCemus / play-redis

Play framework 2 cache plugin as an adapter to redis-server
Mozilla Public License 2.0
164 stars 44 forks source link

java.lang.ClassNotFoundException with akka #246

Closed arigoldx closed 3 years ago

arigoldx commented 3 years ago

Description

I should start this by saying that this might be more Akka + Play related than play-redis but I'm hoping (🤞) that maybe you've come across this.

Everything was working for me perfectly using Akka with jackson json serialization and a standalone AWS "cluster". So I opened a PR. Two colleagues tried to run my PR on their own machine and ran into the following error which I can't reproduce, even when I clone our repo from scratch.

The error goes away when we comment out the serialization bindings. For what it's worth, I used to have these bindings in local.conf but then moved them to application.conf after I saw that they worked:

# akka serialization for redis
akka {
  actor {
    serializers {
      jackson-json = "akka.serialization.jackson.JacksonJsonSerializer"
    }

    serialization-bindings {
      "java.util.ArrayList" = jackson-json
      "models.BaseModel" = jackson-json
      "<another model>" = jackson-json
    }
  }
}

Again, I know this is a shot in the dark but here's the full error:

[error] java.lang.ClassNotFoundException: models.BaseModel
[error]     at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[error]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error]     at java.lang.Class.forName0(Native Method)
[error]     at java.lang.Class.forName(Class.java:348)
[error]     at akka.actor.ReflectiveDynamicAccess.$anonfun$getClassFor$1(ReflectiveDynamicAccess.scala:29)
[error]     at scala.util.Try$.apply(Try.scala:210)
[error]     at akka.actor.ReflectiveDynamicAccess.getClassFor(ReflectiveDynamicAccess.scala:28)
[error]     at akka.serialization.Serialization.$anonfun$bindings$3(Serialization.scala:438)
[error]     at scala.collection.Iterator$$anon$9.next(Iterator.scala:575)
[error]     at scala.collection.immutable.HashMapBuilder.addAll(HashMap.scala:2342)
[error]     at scala.collection.immutable.HashMap$.from(HashMap.scala:2164)
[error]     at scala.collection.immutable.HashMap$.from(HashMap.scala:2140)
[error]     at scala.collection.MapOps$WithFilter.map(Map.scala:352)
[error]     at akka.serialization.Serialization.<init>(Serialization.scala:436)
[error]     at akka.serialization.SerializationExtension$.createExtension(SerializationExtension.scala:18)
[error]     at akka.serialization.SerializationExtension$.createExtension(SerializationExtension.scala:14)
[error]     at akka.actor.ActorSystemImpl.registerExtension(ActorSystem.scala:1158)
[error]     at akka.actor.ActorSystemImpl.$anonfun$loadExtensions$1(ActorSystem.scala:1201)
[error]     at scala.collection.immutable.Vector.foreach(Vector.scala:1794)
[error]     at akka.actor.ActorSystemImpl.loadExtensions$1(ActorSystem.scala:1195)
[error]     at akka.actor.ActorSystemImpl.loadExtensions(ActorSystem.scala:1214)
[error]     at akka.actor.ActorSystemImpl.liftedTree2$1(ActorSystem.scala:1035)
[error]     at akka.actor.ActorSystemImpl._start$lzycompute(ActorSystem.scala:1022)
[error]     at akka.actor.ActorSystemImpl._start(ActorSystem.scala:1022)
[error]     at akka.actor.ActorSystemImpl.start(ActorSystem.scala:1045)
[error]     at akka.actor.ActorSystem$.apply(ActorSystem.scala:272)
[error]     at akka.actor.ActorSystem$.apply(ActorSystem.scala:316)
[error]     at akka.actor.ActorSystem$.apply(ActorSystem.scala:290)
[error]     at play.core.server.DevServerStart$.$anonfun$mainDev$1(DevServerStart.scala:248)
[error]     at play.utils.Threads$.withContextClassLoader(Threads.scala:22)
[error]     at play.core.server.DevServerStart$.mainDev(DevServerStart.scala:76)
[error]     at play.core.server.DevServerStart$.mainDevHttpMode(DevServerStart.scala:50)
[error]     at play.core.server.DevServerStart.mainDevHttpMode(DevServerStart.scala)
[error]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error]     at java.lang.reflect.Method.invoke(Method.java:498)
[error]     at play.runsupport.Reloader$.startDevMode(Reloader.scala:306)
[error]     at play.sbt.run.PlayRun$.devModeServer$lzycompute$1(PlayRun.scala:98)
[error]     at play.sbt.run.PlayRun$.devModeServer$1(PlayRun.scala:81)
[error]     at play.sbt.run.PlayRun$.$anonfun$playRunTask$3(PlayRun.scala:105)
[error]     at play.sbt.run.PlayRun$.$anonfun$playRunTask$3$adapted(PlayRun.scala:67)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)

Setup

Version of play-redis 2.6.1 Version of Scala 2.13.2 Version of Play 2.8.1

(Thanks for the :eyes:!)

KarelCemus commented 3 years ago

Sorry, it is hard to tell what is wrong without having it in my hand. My personal experience is that when there are multiple classloaders, each of them might read a different classpath and they might not see the classes loaded by other classloaders. However, this is usually the issue with enterprise java, not with scala's frameworks. So sorry, don't know. If I were you, I'd dig into the classloaders to check how many are there and whether the serializer uses the correct classloader to load the BaseModel