diff --git a/akka-actor-tests/src/test/scala/akka/serialization/SerializeSpec.scala b/akka-actor-tests/src/test/scala/akka/serialization/SerializeSpec.scala index 499d214ff8..3b0b6ea5bc 100644 --- a/akka-actor-tests/src/test/scala/akka/serialization/SerializeSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/serialization/SerializeSpec.scala @@ -7,10 +7,9 @@ package akka.serialization import akka.serialization.Serialization._ import scala.reflect._ import akka.testkit.AkkaSpec -import akka.actor.{ ActorSystem, ActorSystemImpl } -import java.io.{ ObjectInputStream, ByteArrayInputStream, ByteArrayOutputStream, ObjectOutputStream } -import akka.actor.DeadLetterActorRef import com.typesafe.config.ConfigFactory +import akka.actor._ +import java.io._ object SerializeSpec { @@ -94,6 +93,22 @@ class SerializeSpec extends AkkaSpec(SerializeSpec.serializationConf) { } } + "not serialize ActorCell" in { + val a = system.actorOf(Props(new Actor { + def receive = { + case o: ObjectOutputStream ⇒ + try { + o.writeObject(this) + } catch { + case _: NotSerializableException ⇒ testActor ! "pass" + } + } + })) + a ! new ObjectOutputStream(new ByteArrayOutputStream()) + expectMsg("pass") + a.stop() + } + "serialize DeadLetterActorRef" in { val outbuf = new ByteArrayOutputStream() val out = new ObjectOutputStream(outbuf) diff --git a/akka-actor/src/main/scala/akka/actor/Actor.scala b/akka-actor/src/main/scala/akka/actor/Actor.scala index 0a21cd4c3d..a7e6fac96c 100644 --- a/akka-actor/src/main/scala/akka/actor/Actor.scala +++ b/akka-actor/src/main/scala/akka/actor/Actor.scala @@ -185,7 +185,6 @@ trait Actor { * [[akka.actor.UntypedActorContext]], which is the Java API of the actor * context. */ - @transient protected[akka] implicit val context: ActorContext = { val contextStack = ActorCell.contextStack.get diff --git a/akka-actor/src/main/scala/akka/actor/ActorCell.scala b/akka-actor/src/main/scala/akka/actor/ActorCell.scala index 084fc6c194..c17924c56c 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorCell.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorCell.scala @@ -12,6 +12,7 @@ import java.util.concurrent.TimeUnit.MILLISECONDS import akka.event.Logging.{ Debug, Warning, Error } import akka.util.{ Duration, Helpers } import akka.japi.Procedure +import java.io.{ NotSerializableException, ObjectOutputStream } /** * The actor context - the view of the actor cell from the actor. @@ -111,6 +112,9 @@ trait ActorContext extends ActorRefFactory { * @return the provided ActorRef */ def unwatch(subject: ActorRef): ActorRef + + final protected def writeObject(o: ObjectOutputStream): Unit = + throw new NotSerializableException("ActorContext is not serializable!") } trait UntypedActorContext extends ActorContext {