I'm using Play Framework 2.4.6 with Scala 2.11.8.
The following code throws an NPE:
   val id = ???
   val url = s"/api/customer/$id"
   val request: WSRequest = dependencies.wsClient.url(url)
   val result = request.get()With the following stack trace:
   java.lang.NullPointerException: scheme
      at com.ning.http.client.uri.Uri.<init>(Uri.java:56)
      at com.ning.http.client.uri.Uri.create(Uri.java:32)
      at com.ning.http.client.uri.Uri.create(Uri.java:25)
      at com.ning.http.client.RequestBuilderBase.setUrl(RequestBuilderBase.java:307)
      at com.ning.http.client.RequestBuilder.setUrl(RequestBuilder.java:165)
      at play.api.libs.ws.ning.NingWSRequest.buildRequest(NingWS.scala:218)
      at play.api.libs.ws.ning.NingWSRequest.execute(NingWS.scala:128)
      at play.api.libs.ws.WSRequest$class.get(WS.scala:408)
      at play.api.libs.ws.ning.NingWSRequest.get(NingWS.scala:81)It's been a while since I last saw a NullPointerException in Scala ;). However, it took me and my team way too long to figure out that the issue was simply that we neglected to give a well-formed uri. (Should have been something like
s"http://localhost:9000/api/customer/$id".) At first, we thought something was wrong with our dependency injection.
I was wondering, is it possible for Play to wrap this NPE and change it into a more helpful error message, like "invalid URI" or something? Maybe wrapped in an exception that isn't a NullPointerException ;) ?
I've asked the maintainer of AsyncHttpClient, but he didn't seem receptive to the idea:
https://github.com/AsyncHttpClient/async-http-client/issues/1149What's your take on this?
Regards,
Jan