diff --git a/akka-core/src/main/scala/actor/Actor.scala b/akka-core/src/main/scala/actor/Actor.scala
index 3b7d62f97f..4c19e9b115 100644
--- a/akka-core/src/main/scala/actor/Actor.scala
+++ b/akka-core/src/main/scala/actor/Actor.scala
@@ -228,12 +228,11 @@ object Actor extends Logging {
def spawn(body: => Unit): Unit = {
case object Spawn
actorOf(new Actor() {
- self.start
- self ! Spawn
def receive = {
case Spawn => body; self.stop
}
- })
+ }).start ! Spawn
+
}
}
@@ -413,6 +412,22 @@ trait Actor extends Logging {
*/
def initTransactionalState {}
+ /**
+ * Use reply(..) to reply with a message to the original sender of the message currently
+ * being processed.
+ *
reply_?(..) to reply with a message to the original sender of the message currently
+ * being processed.
+ *
+ * Returns true if reply was sent, and false if unable to determine what to reply to.
+ */
+ def reply_?(message: Any): Boolean = self.reply_?(message)
+
// =========================================
// ==== INTERNAL IMPLEMENTATION DETAILS ====
// =========================================
diff --git a/akka-core/src/main/scala/dispatch/MessageHandling.scala b/akka-core/src/main/scala/dispatch/MessageHandling.scala
index fbf52224ce..54d627258d 100644
--- a/akka-core/src/main/scala/dispatch/MessageHandling.scala
+++ b/akka-core/src/main/scala/dispatch/MessageHandling.scala
@@ -7,7 +7,7 @@ package se.scalablesolutions.akka.dispatch
import java.util.List
import se.scalablesolutions.akka.util.{HashCode, Logging}
-import se.scalablesolutions.akka.actor.{Actor, ActorRef}
+import se.scalablesolutions.akka.actor.{Actor, ActorRef, ActorInitializationException}
import java.util.concurrent.ConcurrentHashMap
@@ -23,7 +23,12 @@ final class MessageInvocation(val receiver: ActorRef,
val transactionSet: Option[CountDownCommitBarrier]) {
if (receiver eq null) throw new IllegalArgumentException("receiver is null")
- def invoke = receiver.invoke(this)
+ def invoke = try {
+ receiver.invoke(this)
+ } catch {
+ case e: NullPointerException => throw new ActorInitializationException(
+ "Don't call 'self ! message' in the Actor's constructor (e.g. body of the class).")
+ }
def send = receiver.dispatcher.dispatch(this)