From 7ce4765fec01119cf9a0f153280e6fb82513d2ee Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 22 Feb 2012 15:34:43 +0100 Subject: [PATCH] do newActor() and preRestart() in the right order, see #1854 --- .../scala/akka/actor/SupervisorMiscSpec.scala | 17 +++++++++++++++++ .../src/main/scala/akka/actor/ActorCell.scala | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/akka-actor-tests/src/test/scala/akka/actor/SupervisorMiscSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/SupervisorMiscSpec.scala index caeacfb3db..f644842591 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/SupervisorMiscSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/SupervisorMiscSpec.scala @@ -60,5 +60,22 @@ class SupervisorMiscSpec extends AkkaSpec(SupervisorMiscSpec.config) with Defaul assert(Await.result(actor4 ? "status", timeout.duration) == "OK", "actor4 is shutdown") } } + + "be able to create named children in its constructor" in { + val a = system.actorOf(Props(new Actor { + context.actorOf(Props.empty, "bob") + def receive = { + case x: Exception ⇒ throw x + } + override def preStart(): Unit = testActor ! "preStart" + })) + val m = "weird message" + EventFilter[Exception](m, occurrences = 1) intercept { + a ! new Exception(m) + } + expectMsg("preStart") + expectMsg("preStart") + a.isTerminated must be(false) + } } } diff --git a/akka-actor/src/main/scala/akka/actor/ActorCell.scala b/akka-actor/src/main/scala/akka/actor/ActorCell.scala index 39bd52aa87..b46d95b669 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorCell.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorCell.scala @@ -389,7 +389,6 @@ private[akka] class ActorCell( def recreate(cause: Throwable): Unit = try { val failedActor = actor if (system.settings.DebugLifecycle) system.eventStream.publish(Debug(self.path.toString, clazz(failedActor), "restarting")) - val freshActor = newActor() if (failedActor ne null) { val c = currentMessage //One read only plz try { @@ -398,6 +397,7 @@ private[akka] class ActorCell( clearActorFields() } } + val freshActor = newActor() actor = freshActor // assign it here so if preStart fails, we can null out the sef-refs next call freshActor.postRestart(cause) if (system.settings.DebugLifecycle) system.eventStream.publish(Debug(self.path.toString, clazz(freshActor), "restarted"))