Re: [akka-user] NullPointerException when concatenating routes (akka-http)

2016-03-29 Thread Konrad Malawski


-- 
Cheers,
Konrad 'ktoso’ Malawski
Akka @ Lightbend

On 29 March 2016 at 04:28:40, Pouria Mellati (pou...@takor.com.au) wrote:

Thanks Konrad, this should fix the issue!
Yup, happy hakking!



I think this sort of issue should be pointed out by the compiler, rather than 
at runtime. Not sure if it is possible though.
In simple cases Scala actually does notify about that, simple forward 
references etc.

In more complex cases it's not trivial sadly so it doesn't (nowadays, perhaps 
it can be improved in future scalac versions).



-- Konrad

-- 
>>  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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] NullPointerException when concatenating routes (akka-http)

2016-03-28 Thread Pouria Mellati
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
> Akka  @ Lightbend 
> 
>
> On 24 March 2016 at 20:28:08, Pouria Mellati (pou...@takor.com.au 
> ) 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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] NullPointerException when concatenating routes (akka-http)

2016-03-24 Thread Konrad Malawski
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
Akka @ Lightbend

On 24 March 2016 at 20:28:08, Pouria Mellati (pou...@takor.com.au) 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:na]


        at 
akka.http.scaladsl.server.directives.ExecutionDirectives$$anonfun$handleExceptions$1$$anonfun$apply$1.apply(ExecutionDirectives.scala:23)
 ~[akka-http-experimental_2.11-2.0.2.jar:na]


        at 
akka.http.scaladsl.server.Route$$anonfun$asyncHandler$1.apply(Route.scala:64) 
~[akka-http-experimental_2.11-2.0.2.jar:na]


        at 
akka.http.scaladsl.server.Route$$anonfun$asyncHandler$1.apply(Route.scala:63) 
~[akka-http-experimental_2.11-2.0.2.jar:na]


        at 
akka.stream.impl.fusing.MapAsync$$anon$9$$anon$10.onPush(Ops.scala:590) 
~[akka-stream-experimental_2.11-2.0.2.jar:na]


        at 
akka.stream.impl.fusing.GraphInterpreter.processElement$1(GraphInterpreter.scala:575)
 ~[akka-stream-experimental_2.11-2.0.2.jar:na]


        at 
akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:586)
 ~[akka-stream-experimental_2.11-2.0.2.jar:na]


        at 
akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:533) 
~[akka-stream-experimental_2.11-2.0.2.jar:na]


        at 
akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:445)
 ~[akka-stream-experimental_2.11-2.0.2.jar:na]


        at 
akka.stream.impl.fusing.GraphInterpreterShell.receive(ActorGraphInterpreter.scala:400)
 ~[akka-stream-experimental_2.11-2.0.2.jar:na]


        at