gettyimages / spray-swagger

Apache License 2.0
140 stars 50 forks source link

Runtime java.lang.NullPointerException #6

Closed lloydmeta closed 10 years ago

lloydmeta commented 10 years ago

I have sample project here that I'm using to try out your lib :)

Unfortunately, when I run it (just container:start from sbt for now), it dies with the following trace caused by a java.lang.NullPointerException. I've declared the modelTypes and also annotated the model; what could be missing ?

> [ERROR] [03/08/2014 23:30:46.830] [beachape-akka.actor.default-dispatcher-4] [akka://beachape/user/$a] null
akka.actor.ActorInitializationException: exception during creation
    at akka.actor.ActorInitializationException$.apply(Actor.scala:164)
    at akka.actor.ActorCell.create(ActorCell.scala:596)
    at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:456)
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:478)
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:263)
    at akka.dispatch.Mailbox.run(Mailbox.scala:219)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.lang.NullPointerException
    at com.gettyimages.spray.swagger.SwaggerModelBuilder.<init>(SwaggerModelBuilder.scala:30)
    at com.gettyimages.spray.swagger.SwaggerApiBuilder.<init>(SwaggerApiBuilder.scala:43)
    at com.gettyimages.spray.swagger.SwaggerHttpService$class.$init$(SwaggerHttpService.scala:49)
    at com.beachape.controllers.ApiServiceActor.<init>(ApiService.scala:16)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.lang.Class.newInstance(Class.java:374)
    at akka.util.Reflect$.instantiate(Reflect.scala:45)
    at akka.actor.NoArgsReflectConstructor.produce(Props.scala:358)
    at akka.actor.Props.newActor(Props.scala:249)
    at akka.actor.ActorCell.newActor(ActorCell.scala:552)
    at akka.actor.ActorCell.create(ActorCell.scala:578)
    ... 9 more
gagnechris commented 10 years ago

We haven't tried this lib with Akka 2.3 and Spray 1.3 yet, we're still on Akka 2.2.3 and Spray 1.2.

I forked your repo and tried to get things working with the downgraded version of Akka (2.2.3), just to see things working. Please see commit: https://github.com/gagnechris/spray-servlet-scratchpad/commit/7bbc41c35bf0c522c575a37713ffbb72dc64aeee with my changes.

These changes resolve the exceptions you were seeing, but I was unable to get the routing working (need some more time to investigate). Please take a look at these changes and let me know how you make out. Hopefully this gives you the push forward you need.

lloydmeta commented 10 years ago

@gagnechris thanks a lot ! Among the other changes, it didn't even occur to me to look at version differences either.

I'll have a look and see if I can get the routing working with your changes.

Again, I really appreciate it !

lloydmeta commented 10 years ago

I got this working now on lloydmeta/spray-servlet-scratchpad so I'll close this issue.

It seems the most important part was to have the SwaggerHttpService trait instantiated as it's own separate object rather than extended as part of an existing object that already extends HttpService. Then, compose your existing routes with the .routes method of that SwaggerHttpService object, like the way you did.

If you want, you can check it out by going to /swagger/ of my project (works with Akka 2.3 and Spray 1.3 :) )

Thanks a lot for the help!