Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Nullpointer Exception #17

Closed
AntonFagerberg opened this issue May 15, 2013 · 1 comment
Closed

Nullpointer Exception #17

AntonFagerberg opened this issue May 15, 2013 · 1 comment

Comments

@AntonFagerberg
Copy link
Contributor

I get a very weird nullpointer exception which happens when I append a spaces to parameters in querystrings but only on certain URLs. I can't find a pattern or cause but I can reproduce it by doing this:

// OK: Works
println(Http("https://www.google.com/?a=b").options(HttpOptions.connTimeout(10000), HttpOptions.readTimeout(10000)).asString)

// OK: 404 HttpException
println(Http("https://www.google.com/?a= b").options(HttpOptions.connTimeout(10000), HttpOptions.readTimeout(10000)).asString)
println(Http("https://api.instagram.com/v1/users/12895238/?a=b").options(HttpOptions.connTimeout(10000), HttpOptions.readTimeout(10000)).asString)
println(Http("https://api.instagram.com/v1/users/ 12895238/?a=b").options(HttpOptions.connTimeout(10000), HttpOptions.readTimeout(10000)).asString)
println(Http("https://api.instagram.com/v1/users/12895238/?a=b ").options(HttpOptions.connTimeout(10000), HttpOptions.readTimeout(10000)).asString)

// NOT OK: NullPointerException
println(Http("https://api.instagram.com/v1/users/12895238/?a =b").options(HttpOptions.connTimeout(10000), HttpOptions.readTimeout(10000)).asString)
println(Http("https://api.instagram.com/v1/users/12895238/? a=b").options(HttpOptions.connTimeout(10000), HttpOptions.readTimeout(10000)).asString)

It might be related to Issue #8 but it seems to happen in another part of the code:

Exception in thread "main" java.lang.NullPointerException
    at scalaj.http.Http$.tryParse(Http.scala:155)
    at scalaj.http.Http$Request.liftedTree1$1(Http.scala:107)
    at scalaj.http.Http$Request.process(Http.scala:103)
    at scalaj.http.Http$Request.apply(Http.scala:90)
    at scalaj.http.Http$Request.asString(Http.scala:133)
@hoffrocket
Copy link
Member

There was a bug in the exception handling which is now fixed in 0.3.9. Sorry for the long delay in this. Here's what the output will look like with the fix

scala> Http("https://api.instagram.com/v1/users/12895238/?a =b").asString
scalaj.http.HttpException: 400: BAD_REQUEST
    at scalaj.http.Http$Request.process(Http.scala:119)
    at scalaj.http.Http$Request.apply(Http.scala:96)
    at scalaj.http.Http$Request.asString(Http.scala:145)
    at .<init>(<console>:9)
    at .<clinit>(<console>)
    at .<init>(<console>:11)
    at .<clinit>(<console>)
    at $print(<console>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
    at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:914)
    at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:546)
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:577)
    at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:543)
    at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:694)
    at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:745)
    at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:651)
    at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:542)
    at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:550)
    at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
    at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:851)
    at xsbt.ConsoleInterface.run(ConsoleInterface.scala:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:73)
    at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:64)
    at sbt.Console.console0$1(Console.scala:23)
    at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24)
    at sbt.TrapExit$.executeMain$1(TrapExit.scala:33)
    at sbt.TrapExit$$anon$1.run(TrapExit.scala:42)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://api.instagram.com/v1/users/12895238/?a =b
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
    at scalaj.http.Http$Request$$anonfun$apply$1.apply(Http.scala:96)
    at scalaj.http.Http$Request$$anonfun$apply$1.apply(Http.scala:96)
    at scalaj.http.Http$Request.process(Http.scala:116)
    ... 34 more

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants