diff --git a/akka-actor/src/main/scala/akka/AkkaException.scala b/akka-actor/src/main/scala/akka/AkkaException.scala index 5fbf84ed67..ae245e3591 100644 --- a/akka-actor/src/main/scala/akka/AkkaException.scala +++ b/akka-actor/src/main/scala/akka/AkkaException.scala @@ -20,6 +20,20 @@ class AkkaException(message: String, cause: Throwable) extends RuntimeException( override def toString(): String = uuid + super.toString() } +/** + * Mix in this trait to suppress the StackTrace for the instance of the exception but not the cause, + * scala.util.control.NoStackTrace suppresses all the StackTraces. + */ +trait OnlyCauseStackTrace { self: Throwable ⇒ + override def fillInStackTrace(): Throwable = { + setStackTrace(getCause match { + case null ⇒ Array.empty + case some ⇒ some.getStackTrace + }) + this + } +} + /** * This exception is thrown when Akka detects a problem with the provided configuration */ diff --git a/akka-remote/src/main/scala/akka/remote/Endpoint.scala b/akka-remote/src/main/scala/akka/remote/Endpoint.scala index 915c85e9e7..7b83673c78 100644 --- a/akka-remote/src/main/scala/akka/remote/Endpoint.scala +++ b/akka-remote/src/main/scala/akka/remote/Endpoint.scala @@ -1,6 +1,6 @@ package akka.remote -import akka.AkkaException +import akka.{ OnlyCauseStackTrace, AkkaException } import akka.actor._ import akka.dispatch.SystemMessage import akka.event.LoggingAdapter @@ -106,7 +106,7 @@ private[remote] object EndpointWriter { case object Writing extends State } -private[remote] class EndpointException(msg: String, cause: Throwable) extends AkkaException(msg, cause) with NoStackTrace { +private[remote] class EndpointException(msg: String, cause: Throwable) extends AkkaException(msg, cause) with OnlyCauseStackTrace { def this(msg: String) = this(msg, null) } diff --git a/akka-remote/src/main/scala/akka/remote/transport/AkkaProtocolTransport.scala b/akka-remote/src/main/scala/akka/remote/transport/AkkaProtocolTransport.scala index 398ff6f950..d9176c9f7b 100644 --- a/akka-remote/src/main/scala/akka/remote/transport/AkkaProtocolTransport.scala +++ b/akka-remote/src/main/scala/akka/remote/transport/AkkaProtocolTransport.scala @@ -1,6 +1,6 @@ package akka.remote.transport -import akka.AkkaException +import akka.{ OnlyCauseStackTrace, AkkaException } import akka.actor.SupervisorStrategy.Stop import akka.actor._ import akka.pattern.pipe @@ -19,7 +19,7 @@ import scala.util.{ Success, Failure } import scala.collection.immutable import akka.remote.transport.ActorTransportAdapter._ -class AkkaProtocolException(msg: String, cause: Throwable) extends AkkaException(msg, cause) +class AkkaProtocolException(msg: String, cause: Throwable) extends AkkaException(msg, cause) with OnlyCauseStackTrace private[remote] class AkkaProtocolSettings(config: Config) {