0
package models

import play.api.libs.json.{Json, OFormat}
import reactivemongo.bson.{BSONLong, BSONObjectID}

case class SavedPostOrBlog(
                          _id:Option[BSONObjectID],
                          postOrBlogId:BSONObjectID,
                          discussGroupId:Option[BSONObjectID], 
                          saverId:BSONObjectID,
                          isQPost:Option[Boolean]=None,
                          isArticle:Option[Boolean]=None, 
                          test : BSONLong = BSONLong.apply(12334)
                          )


object SavedPostOrBlogJsonFormat{



  import reactivemongo.play.json._

  implicit val spb: OFormat[SavedPostOrBlog] = Json.format[SavedPostOrBlog]

}

[error] a.a.ActorSystemImpl - Uncaught error from thread [application-dbContext-
dispatcher-37]: models.SavedPostOrBlog.<init>(Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lscala/Option;)V, shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[application]
java.lang.NoSuchMethodError: models.SavedPostOrBlog.<init>(Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lscala/Option;)V
        at controllers.postActions.SavePostController.$anonfun$savePost$8(SavePostController.scala:96)
        at controllers.postActions.SavePostController.checkDGroupMemberShip(SavePostController.scala:157)
        at controllers.postActions.SavePostController.$anonfun$savePost$4(SavePostController.scala:93)
        at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:433)
        at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
        at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:92)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
        at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
        at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:92)
        at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41)
[info] p.c.s.AkkaHttpServer - Stopping server...
[info] p.m.r.DefaultReactiveMongoApi - ReactiveMongoApi stopping...
[INFO] [04/02/2020 12:49:00.178] [reactivemongo-akka.actor.default-dispatcher-12] [akka://reactivemongo/user/Connection-1] Message [reactivemongo.core.actors.ChannelDisconnected] without sender to Actor[akka://reactivemongo/user/Connection-1#1685282110] was not delivered. [1] dead letters encountered. If this is not an expected behavior, then [Actor[akka://reactivemongo/user/Connection-1#1685282110]] may have terminated unexpectedly, This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[info] r.c.a.MongoDBSystem - [Supervisor-2/Connection-1] Stopping the MongoDBSystem
[info] p.m.r.DefaultReactiveMongoApi - ReactiveMongoApi connections are stopped
[info] r.api.Driver - [Supervisor-2] Closing instance of ReactiveMongo driver
[info] r.api.Driver - [Supervisor-2] Stopping the monitor...
[DEBUG] [04/02/2020 12:49:00.182] [reactivemongo-akka.actor.default-dispatcher-2] [EventStream] shutting down: StandardOutLogger
[info] r.c.n.ChannelFactory - [Supervisor-2/Connection-1] Cannot create channel to '127.0.0.1:27017' from inactive factory
[warn] r.c.a.MongoDBSystem - [Supervisor-2/Connection-1] Cannot create connection for Node(127.0.0.1:27017,Primary,Vector(Connection([id: 0x03a83e6d, L:0.0.0.0/0.0.0.0:58166 ! R:/127.0.0.1:27017],Connecting,Set(Authenticated(admin,dbReadWrite)),None)),Set(Authenticated(admin,dbReadWrite)),None,ProtocolMetadata(2.6, 3.6),PingInfo(6760584, 0, -1, None),false)
reactivemongo.core.errors.GenericDriverException: MongoError['Cannot create channel to '127.0.0.1:27017' from inactive factory (Supervisor-2/Connection-1)']

Without test property in SavedPostOrBlog model query runs okay, but when I add test property of BSONLong, the jvm crash.

Here is the query:

def createDocument(postOrBlogId: BSONObjectID,
                   saverId: BSONObjectID, savedPostOrBlog: SavedPostOrBlog): Future[UpdateWriteResult] =
  collection.map(_.update(true).one(Json.obj("postOrBlogId" -> postOrBlogId, "saverId" -> saverId), savedPostOrBlog, upsert = true)).flatten

The reactiveMongo dependency : "org.reactivemongo" %% "play2-reactivemongo" % "0.18.4-play27"

John
  • 2,633
  • 4
  • 19
  • 34
  • Check your dependencies. `NoSuckMethod` means the runtime deps are not those used to compiled, or at least not compatible. – cchantep Apr 02 '20 at 17:45

2 Answers2

1

I had a similar issue where the query crashed if i put a certain value in the query field, and worked if i didn't put this certain value.

It turned out that the serializer i created was missing this field's serialization to JSON (or document)

And i didn't get a corrsenponding error but had to play with debug in order to figure it out ...

I think that:

implicit val spb: OFormat[SavedPostOrBlog] = Json.format[SavedPostOrBlog]

is not enough, try to also provide OFormat for BSONLong as an implicit val

0

The problem is when in development stage we try to compile in sbt by compile command or hot reload, sometimes it happened that

  1. compiler misses some missing method errors, and shows compilation done successfully, but that is not true.
  2. Sometimes compiler failed to create compile time reactive-mongo's some macro activities so some methods are not found on runtime.

These two I find the reasons behind application crush. If I clean and compile again the project- Either will be able to catch the first time not found error or in case of 2nd problem model related macro activities will be done properly. So runtime error will be removed.

John
  • 2,633
  • 4
  • 19
  • 34