Thanks Konrad, this should fix the issue! I think this sort of issue should be pointed out by the compiler, rather than at runtime. Not sure if it is possible though.
On Friday, March 25, 2016 at 3:32:17 AM UTC+8, Konrad Malawski wrote: > > Hi there, > you're running into "val referring to not yet initialized val" problems. > > This can happen if you have traits linearize ( > http://ktoso.github.io/scala-types-of-types/#type-linearization-vs-the-diamond-problem > ), > in such order that one trait refers with a `val` to another before the > first one has a chance to initialize etc. > > In general if you have a lot of routes refering to one another I'd > recommend making them `lazy val` instead. > > // FYI: This is a general Scala thing, it could happen with "val x = a + > b" if b was not yet initialized. > > Hope this helps, happy hakking! > > > -- > Cheers, > Konrad 'ktoso’ Malawski > <http://akka.io>Akka <http://akka.io> @ Lightbend <http://typesafe.com> > <http://lightbend.com> > > On 24 March 2016 at 20:28:08, Pouria Mellati ([email protected] > <javascript:>) wrote: > > I think I've ran into a akka-http bug. > > I have a big-ass route: > > val route = pathPrefix("users") { > ... > } > > > And wanted to add this new route to it: > > val blockingEndpoint = (pathPrefix("users" / "blocked") & authentication) > {issuerId => > path(JavaUUID) {blockeeId => > put { > complete{HttpResponse(NotImplemented)} > } ~ > delete { > complete{HttpResponse(NotImplemented)} > } > } ~ > get { > complete{HttpResponse(NotImplemented)} > } > } > > > > Now, if I simply do: > > > val route = pathPrefix("users") { > ... > } ~ > blockingEndpoint > > > I will get the following NPE if I send a request towards the routes in > blockingEndpoint: > > java.lang.NullPointerException: null > > at akka.http.scaladsl.server. > RouteConcatenation$RouteWithConcatenation$$anonfun$$tilde$1$$anonfun$apply$1 > .apply(RouteConcatenation.scala:28) ~[akka-http-experimental_2.11-2.0. > 2.jar:na] > > at akka.http.scaladsl.server. > RouteConcatenation$RouteWithConcatenation$$anonfun$$tilde$1$$anonfun$apply$1 > .apply(RouteConcatenation.scala:25) ~[akka-http-experimental_2.11-2.0. > 2.jar:na] > > at akka.http.scaladsl.util.FastFuture$. > akka$http$scaladsl$util$FastFuture$$strictTransform$1(FastFuture.scala:41) > ~[akka-http-core-experimental_2.11-2.0.2.jar:na] > > at akka.http.scaladsl.util.FastFuture$.transformWith$extension1( > FastFuture.scala:45) ~[akka-http-core-experimental_2.11-2.0.2.jar:na] > > at akka.http.scaladsl.util.FastFuture$.flatMap$extension( > FastFuture.scala:26) ~[akka-http-core-experimental_2.11-2.0.2.jar:na] > > at akka.http.scaladsl.server. > RouteConcatenation$RouteWithConcatenation$$anonfun$$tilde$1.apply( > RouteConcatenation.scala:25) ~[akka-http-experimental_2.11-2.0.2.jar:na] > > at akka.http.scaladsl.server. > RouteConcatenation$RouteWithConcatenation$$anonfun$$tilde$1.apply( > RouteConcatenation.scala:23) ~[akka-http-experimental_2.11-2.0.2.jar:na] > > at akka.http.scaladsl.server.directives. > BasicDirectives$$anonfun$mapRouteResultWith$1$$anonfun$apply$4.apply( > BasicDirectives.scala:35) ~[akka-http-experimental_2.11-2.0.2.jar:na] > > at akka.http.scaladsl.server.directives. > BasicDirectives$$anonfun$mapRouteResultWith$1$$anonfun$apply$4.apply( > BasicDirectives.scala:35) ~[akka-http-experimental_2.11-2.0.2.jar:na] > > at akka.http.scaladsl.server.directives. > BasicDirectives$$anonfun$textract$1$$anonfun$apply$5.apply(BasicDirectives > .scala:88) ~[akka-http-experimental_2.11-2.0.2.jar:na] > > at akka.http.scaladsl.server.directives. > BasicDirectives$$anonfun$textract$1$$anonfun$apply$5.apply(BasicDirectives > .scala:88) ~[akka-http-experimental_2.11-2.0.2.jar:na] > > at akka.http.scaladsl.server.directives. > ExecutionDirectives$$anonfun$handleExceptions$1$$anonfun$apply$1.apply( > ExecutionDirectives.scala:27) ~[akka-http-experimental_2.11-2.0.2.jar: > > ... -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
