From 34499e122d79a84004145cece16b8001e7784492 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Fri, 6 Feb 2015 13:31:43 -0500 Subject: [PATCH] =act #16745 Improve error logging in akka.io.SelectionHandler When a java.net.BindException occurs, it produces an exception with a cause and message that is "null" because it's cause returns no message. This notably occurs when a java.net.BindException occurs during construction of a TCP selector. This patch causes a log message like this: java.net.BindException: Can't assign requested address instead of like this: null which is quite a bit more helpful when diagnosing connection issues. --- akka-actor/src/main/scala/akka/io/SelectionHandler.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/akka-actor/src/main/scala/akka/io/SelectionHandler.scala b/akka-actor/src/main/scala/akka/io/SelectionHandler.scala index 4075a1e95b..e8ae60acc2 100644 --- a/akka-actor/src/main/scala/akka/io/SelectionHandler.scala +++ b/akka-actor/src/main/scala/akka/io/SelectionHandler.scala @@ -257,7 +257,12 @@ private[io] class SelectionHandler(settings: SelectionHandlerSettings) extends A decision: SupervisorStrategy.Directive): Unit = try { val logMessage = cause match { - case e: ActorInitializationException if e.getCause ne null ⇒ e.getCause.getMessage + case e: ActorInitializationException if (e.getCause ne null) && (e.getCause.getMessage ne null) ⇒ e.getCause.getMessage + case e: ActorInitializationException if e.getCause ne null ⇒ + e.getCause match { + case ie: java.lang.reflect.InvocationTargetException ⇒ ie.getTargetException.toString + case t: Throwable ⇒ Logging.simpleName(t) + } case e ⇒ e.getMessage } context.system.eventStream.publish(