[2.5.0 Scala Compile-time DI] java.lang.InstantiationException: play.api.libs.Crypto

85 views
Skip to first unread message

Evan Bennett

unread,
Mar 14, 2016, 11:43:06 PM3/14/16
to play-framework
I have upgraded my projects to Play 2.5 and I am left with an issue that I have been unable to solve. Any assistance would be greatly appreciated.

java.lang.InstantiationException: play.api.libs.Crypto
        at java.lang.Class.newInstance(Unknown Source)
        at play.api.inject.NewInstanceInjector$.instanceOf(Injector.scala:51)
        at play.api.inject.SimpleInjector$$anonfun$instanceOf$1.apply(Injector.scala:87)
        at scala.collection.MapLike$class.getOrElse(MapLike.scala:128)
        at scala.collection.AbstractMap.getOrElse(Map.scala:59)
        at play.api.inject.SimpleInjector.instanceOf(Injector.scala:87)
        at play.api.inject.SimpleInjector.instanceOf(Injector.scala:82)
        at play.api.Application$$anonfun$instanceCache$1.apply(Application.scala:214)
        at play.api.Application$$anonfun$instanceCache$1.apply(Application.scala:214)
        at play.utils.InlineCache.fresh(InlineCache.scala:69)
        at play.utils.InlineCache.apply(InlineCache.scala:55)
        at scala.Option.fold(Option.scala:158)
        at play.api.libs.Crypto$.crypto(Crypto.scala:63)
        at play.api.mvc.Session$.cookieSigner(Http.scala:716)
        at play.api.mvc.Session$.cookieSigner(Http.scala:704)
        at play.api.mvc.CookieBaker$class.encode(Http.scala:555)
        at play.api.mvc.Session$.encode(Http.scala:704)
        at play.api.mvc.CookieBaker$class.encodeAsCookie(Http.scala:607)
        at play.api.mvc.Session$.encodeAsCookie(Http.scala:704)
        at play.api.mvc.Result.withSession(Results.scala:139)
        at core.Action$$anonfun$core$Action$$invokeBlockAndProcessResult$2.apply(Action.scala:63)
        at core.Action$$anonfun$core$Action$$invokeBlockAndProcessResult$2.apply(Action.scala:59)
        at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251)
        at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodException: play.api.libs.Crypto.<init>()
        at java.lang.Class.getConstructor0(Unknown Source)
        ... 28 common frames omitted

NOTES:
* This only occurs (so far) when I successfully login, which is the first time that 'Action.scala:63' is run.
* The line 66 only gets executed once I am logged in. (Which I cannot do ATM.)
* Prior to login line 65 executes

I have provided some of my source code, but have removed some that seemed irrelevant:

package core
final class Action(...) extends play.api.mvc.ActionBuilder[ActionBlockArguments] {

   def invokeBlock[A](playRequest: play.api.mvc.Request[A], block: ActionBlockArguments[A] => Future[play.api.mvc.Result]): Future[play.api.mvc.Result] = {
      ...
      invokeBlockAndProcessResult(block)(ActionBlockArguments())
      ...
   }

   private def invokeBlockAndProcessResult[A](block: ActionBlockArguments[A] => Future[play.api.mvc.Result])(implicit actionBlockArguments: ActionBlockArguments[A]): Future[play.api.mvc.Result] = {
      block(actionBlockArguments).flatMap { result =>
         ...
         result match {
            case result: core.Results.LoggedIn => result.withSession(session(result.newUserLogin))                                                          *** LINE 63 ***
            case _: core.Results.LoggedOut => result.withNewSession
            case _ if actionBlockArguments.request.userLogin == null || actionBlockArguments.request.sessionInactive => result
            case _ => result.withSession(session(actionBlockArguments.request.userLogin))
         }
         ...
      }
   }

   private def session(userLogin: core.traits.models.UserLogin)(implicit actionBlockArguments: ActionBlockArguments[_]): play.api.mvc.Session = {
      play.api.mvc.Session(Seq(
         (Action.SESSION_UUID -> userLogin.csrfSessionUuid.value.uuid.toString),
         (Action.SESSION_IP_ADDRESS -> actionBlockArguments.request.playRequest.remoteAddress),
         (Action.SESSION_LAST_ACCESSED -> System.currentTimeMillis.toString)
      ).toMap)
   }
}
object Action {
   val SESSION_IP_ADDRESS = "SESSION_IP_ADDRESS"
   val SESSION_LAST_ACCESSED = "SESSION_LAST_ACCESSED"
   val SESSION_UUID = "SESSION_UUID"
   ...
}

package core
object Results {
   final class LoggedOut(playResult: play.api.mvc.Result) extends play.api.mvc.Result(playResult.header, playResult.body)
   final class LoggedIn(val newUserLogin: core.traits.models.UserLogin, playResult: play.api.mvc.Result) extends play.api.mvc.Result(playResult.header, playResult.body)
   ...
}

Julien Richard-Foy

unread,
Mar 15, 2016, 4:47:42 AM3/15/16
to play-framework
Hi,

I think it has been fixed by this PR: https://github.com/playframework/playframework/pull/5856

Julien Richard-Foy

unread,
Mar 15, 2016, 4:49:10 AM3/15/16
to play-framework
It will be fixed in 2.5.1, but in the meanwhile here is a workaround:


On Tuesday, March 15, 2016 at 4:43:06 AM UTC+1, Evan Bennett wrote:

Evan Bennett

unread,
Mar 15, 2016, 5:18:59 PM3/15/16
to play-fr...@googlegroups.com
Thank you very much.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/c1bebe85-a34b-479f-ac33-4ee874822d6c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
  Evan Bennett
  BInfTech(DataCommunications&SoftwareEng)(QUT) MACS

Greg Methvin

unread,
Mar 15, 2016, 5:26:18 PM3/15/16
to play-framework
If you want a workaround you can add Crypto to the runtime injector yourself: https://github.com/playframework/playframework/pull/5856/files#diff-3b7eaa744ad895d6a36f11720bbfa0acR250


For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Senior Software Engineer

Reply all
Reply to author
Forward
0 new messages