DOCS: Check ComposableActor example works in 2.0.x
Got the following error report on IRC. The code is almost exactly the same as we have in our docs but shows a NPE. It looks like an error due to receive being called before the class is fully initialised. Apparently this could be a bug in 2.0.x. We should write a test and backport it. If it breaks 2.0.x then we will want to update our docs to either fix the problem or remove it as an example.
mikeX: hi, I'm trying to implement the composable actor described in the Akka 2.0.4 documentation, but I'm getting the following error: https://gist.github.com/4202268 The example I'm using is https://gist.github.com/4202263 Any idea what I'm doing wrong? Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37). Type in expressions to have them evaluated. Type :help for more information. scala> Act.main(Array()) scala> [ERROR] [12/04/2012 09:47:39.60] [MySystem-akka.actor.default-dispatcher-2] [akka://MySystem/user/myactor] error while creating actor java.lang.NullPointerException at ComposableActor$class.receive(Act.scala:9) at MyComposableActor.receive(Act.scala:12) at akka.actor.Actor$class.$init$(Actor.scala:343) at MyComposableActor.<init>(Act.scala:12) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at akka.actor.Props$$anonfun$withCreator$2.apply(Props.scala:159) at akka.actor.Props$$anonfun$withCreator$2.apply(Props.scala:159) at akka.actor.ActorCell.newActor(ActorCell.scala:488) at akka.actor.ActorCell.create$1(ActorCell.scala:506) at akka.actor.ActorCell.systemInvoke(ActorCell.scala:600) at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:209) at akka.dispatch.Mailbox.run(Mailbox.scala:178) at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:516) at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479) at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) import akka.actor._ trait ComposableActor extends Actor { private var receives: List[Receive] = List() protected def registerReceive(rec: Receive) { receives = rec :: receives } def receive: Receive = receives reduce { _ orElse _ } } class MyComposableActor extends ComposableActor { override def preStart() { registerReceive({ case "foo" => println("foo") }) registerReceive({ case "bar" => println("bar") }) } } object Act { def main(args: Array[String]) = { val system = ActorSystem("MySystem") val myActor = system.actorOf(Props[MyComposableActor], name = "myactor") myActor ! "foo" } }
Leave a comment
on 2012-12-06 06:15 *
By Rich Dougherty
So the plan:
2.0
provide alternative implementation in docs, if possible (and properly test it)
check docs explain the issue clearly since we made the mistake ourselves
2.1
the code shouldn't need to be changed
actually run code in docs to confirm it works
2.0
provide alternative implementation in docs, if possible (and properly test it)
check docs explain the issue clearly since we made the mistake ourselves
2.1
the code shouldn't need to be changed
actually run code in docs to confirm it works
on 2013-02-20 19:24 *
By Rich Dougherty
Fw port to master: https://github.com/akka/akka/pull/1166