Exception during Actor construction

759 views
Skip to first unread message

Derek Wyatt

unread,
May 21, 2012, 11:03:24 AM5/21/12
to Akka UserGroup
Hi guys,

I wasn't able to find this in the docs, so if I missed it I'd appreciate the RTFM pointer.

I'm wondering why I can't get the exception I throw in the Actor's constructor propagated out to the caller.

class A extends Actor {
throw new Exception("Argh, ye treasure not be here!")
def receive = ...
}

When I instantiate this, I get the following:

[ERROR] [05/21/2012 11:01:34.176] [ActorSystem-akka.actor.default-dispatcher-1] [akka://ActorSystem/user/$a] error while creating actor
java.lang.InstantiationException: Main$$anon$1$ActorName
at java.lang.Class.newInstance0(Class.java:340)
at java.lang.Class.newInstance(Class.java:308)
at akka.actor.Props$$anonfun$apply$1.apply(Props.scala:46)
at akka.actor.Props$$anonfun$apply$1.apply(Props.scala:46)
at akka.actor.ActorCell.newActor(ActorCell.scala:488)
at akka.actor.ActorCell.create$1(ActorCell.scala:506)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:593)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:208)
at akka.dispatch.Mailbox.run(Mailbox.scala:177)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:505)
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)

Is there any way to get the thrown exception propagated out to the caller? The silly example is obviously easy to deal with, but in real life I may get an exception from somewhere way outside my code and it'll probably be a real bear to find in some cases.
signature.asc

√iktor Ҡlang

unread,
May 21, 2012, 11:26:14 AM5/21/12
to akka...@googlegroups.com

It's created async.

Derek Wyatt

unread,
May 21, 2012, 11:42:46 AM5/21/12
to akka...@googlegroups.com
Man, I'm getting deja-vu.  I may have already asked this a long time ago :)

Yeah, it's somewhere buried in the ActorCell that eventually calls the props.creator(), yes?  I've seen the few places where that gets called and it seems as though the only thing that happens is a throw.  I didn't see a log message anywhere in there.  Is it not reasonable to log this as an error?  Presumable the call to the creator can get a 'catch' on it that does a log.error follow by a throw, no?

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

signature.asc

√iktor Ҡlang

unread,
May 21, 2012, 12:38:19 PM5/21/12
to akka...@googlegroups.com

Derek Wyatt

unread,
May 21, 2012, 12:43:08 PM5/21/12
to akka...@googlegroups.com
Interesting...  Perhaps there's something wrong with the plumbing?  The output I showed you below is from 2.0.1 and it's all I get.  The exception that my code throws never shows up; just the InstantiationException.

Is there another release I should try it on?
signature.asc

√iktor Ҡlang

unread,
May 21, 2012, 12:44:18 PM5/21/12
to akka...@googlegroups.com
On Mon, May 21, 2012 at 6:43 PM, Derek Wyatt <de...@derekwyatt.org> wrote:
Interesting...  Perhaps there's something wrong with the plumbing?  The output I showed you below is from 2.0.1 and it's all I get.  The exception that my code throws never shows up; just the InstantiationException.

Is there another release I should try it on?

Try on the latest nightly?

Cheers,

Derek Wyatt

unread,
May 21, 2012, 1:21:12 PM5/21/12
to akka...@googlegroups.com
I did it with the current master - I hope that's appropriate - and I got the same problem:

scala -cp ~/.ivy2/local/com.typesafe.akka/akka-actor/2.1-SNAPSHOT/jars/akka-actor.jar throw.scala
[ERROR] [05/21/2012 13:17:37.805] [ActorSystem-akka.actor.default-dispatcher-2] [akka://ActorSystem/user/$a] error while processing Create()
akka.actor.ActorInitializationException:exception during creation, this problem is likely to occur because the class of the Actor you tried to create is either,
               a non-static inner class (in which case make it a static inner class or use Props(new ...) or Props( new UntypedActorFactory ... )
               or is missing an appropriate, reachable no-args constructor.
            
[dd0a6dc0-a368-11e1-8e55-040ccee0bfb2]
Caused by: java.lang.InstantiationException: Main$$anon$1$ActorName
at java.lang.Class.newInstance0(Class.java:340)
at java.lang.Class.newInstance(Class.java:308)
at akka.actor.FromClassCreator.apply(Props.scala:177)
at akka.actor.FromClassCreator.apply(Props.scala:176)
at akka.actor.ActorCell.newActor(ActorCell.scala:488)
at akka.actor.ActorCell.create$1(ActorCell.scala:506)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:587)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:208)
at akka.dispatch.Mailbox.run(Mailbox.scala:177)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:512)
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)

So I get a log message at ERROR level, but it's not my exception, which is defined as:

import akka.actor._

class ActorName extends Actor {
  throw new Exception("Arrgh, ye treasure not be here!")
  def receive = {
    case _ =>
  }
}

val sys = ActorSystem("ActorSystem")
val a = sys.actorOf(Props[ActorName])

Is this bug-ticket worthy, or am I still missing something?
signature.asc

√iktor Ҡlang

unread,
May 21, 2012, 1:25:36 PM5/21/12
to akka...@googlegroups.com
Ah, good one, I'll add unboxing of InstantiationExceptions.

Derek Wyatt

unread,
May 21, 2012, 1:27:42 PM5/21/12
to akka...@googlegroups.com
Ah, that makes sense.  You just need to dig it out and log it.  Keen.

Thx,
D
signature.asc

√iktor Ҡlang

unread,
May 21, 2012, 1:34:05 PM5/21/12
to akka...@googlegroups.com
Fixed in master, please verify

Derek Wyatt

unread,
May 21, 2012, 1:39:35 PM5/21/12
to akka...@googlegroups.com
No good.

scala -cp ~/.ivy2/local/com.typesafe.akka/akka-actor/2.1-SNAPSHOT/jars/akka-actor.jar throw.scala
[ERROR] [05/21/2012 13:37:36.353] [ActorSystem-akka.actor.default-dispatcher-2] [akka://ActorSystem/user/$a] error while processing Create()
akka.actor.ActorInitializationException:exception during creation, this problem is likely to occur because the class of the Actor you tried to create is either,
               a non-static inner class (in which case make it a static inner class or use Props(new ...) or Props( new UntypedActorFactory ... )
               or is missing an appropriate, reachable no-args constructor.
            
[a76d6ca0-a36b-11e1-85b8-040ccee0bfb2]

I no longer get the stack trace, but the exception message is still missing.
signature.asc

√iktor Ҡlang

unread,
May 21, 2012, 1:50:49 PM5/21/12
to akka...@googlegroups.com
Ah, some old sins in AkkaException are showing their ugly face.

I'll get that sorted while doing my binary compat work.

Cheers,

Derek Wyatt

unread,
May 21, 2012, 1:51:50 PM5/21/12
to akka...@googlegroups.com
That's cool.  I'll write up a ticket, if you like, but otherwise I'll leave it in your capable fingers.
signature.asc

√iktor Ҡlang

unread,
May 21, 2012, 2:21:53 PM5/21/12
to akka...@googlegroups.com
Should be fixed in wip-2006-binary-compat-√ now.

Cheers,

Derek Wyatt

unread,
May 21, 2012, 2:34:45 PM5/21/12
to √iktor Ҡlang, akka...@googlegroups.com
No go.  It's different again, though.  I now no longer see the "guess" message about what it might be, but I still don't see my exception message:

> scala -cp ~/.ivy2/local/com.typesafe.akka/akka-actor/2.1-SNAPSHOT/jars/akka-actor.jar throw.scala   
[ERROR] [05/21/2012 14:33:13.633] [ActorSystem-akka.actor.default-dispatcher-3] [akka://ActorSystem/user/$a] error while processing Create()
signature.asc

√iktor Ҡlang

unread,
May 21, 2012, 3:16:57 PM5/21/12
to Derek Wyatt, akka...@googlegroups.com
Sorry 'bout that,
There were some weird interplay of NoStackTrace trait on ActorInitializationException and actually printing the stacktrace of the cause.

I've verified that it works now on my binary compat branch.

Cheers,
√ 

Derek Wyatt

unread,
May 21, 2012, 7:59:12 PM5/21/12
to √iktor Ҡlang, akka...@googlegroups.com
It still isn't working for me… The output has changed again, so at least something new is happening, but my exception is still being swallowed.

[ERROR] [05/21/2012 19:54:42.497] [T-akka.actor.default-dispatcher-3] [akka://T/user/$a] error while processing Create()
7a0994b2-21ef-4a52-bd0f-43c52a66efb3akka.actor.ActorInitializationException: exception during creation, this problem is likely to occur because the class of the Actor you tried to create is either,
               a non-static inner class (in which case make it a static inner class or use Props(new ...) or Props( new UntypedActorFactory ... )
               or is missing an appropriate, reachable no-args constructor.
            
at akka.actor.ActorCell.create$1(ActorCell.scala:530)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:604)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:215)
at akka.dispatch.Mailbox.run(Mailbox.scala:184)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:574)
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)


The code I was running was this:

import akka.actor._

class ActorName extends Actor {
  throw new Exception("This is a really long exception message with some junk in it so it's easy to SEE @#)(*QG)@(#%)(JGWE()RJG@!)(*&$%()@#&$@#$&*)@#$)^*(@#$)(%*@#^$")
  def receive = { case _ => }
}

val sys = ActorSystem("T")
val a = sys.actorOf(Props[ActorName]) 

Cheers,
Derek
signature.asc

Derek Wyatt

unread,
May 22, 2012, 5:55:01 AM5/22/12
to √iktor Ҡlang, akka...@googlegroups.com
It just hit me that we're probably testing different things.  I've just verified that:

- Props(new ActorName) -- propagates the exception correctly
- Props[ActorName] -- doesn't

Cheers,
Derek
signature.asc

√iktor Ҡlang

unread,
May 22, 2012, 6:14:51 AM5/22/12
to Derek Wyatt, akka...@googlegroups.com
Can't reproduce:

scala> import akka.actor._
import akka.actor._

scala> val as = ActorSystem("foo")
as: akka.actor.ActorSystem = akka://foo

scala> class Foo extends Actor { throw new Exception("pigdog"); def receive = { case _ => println("pigdog") } }
defined class Foo

scala> as.actorOf(Props[Foo])
res0: akka.actor.ActorRef = Actor[akka://foo/user/$a]

scala> [ERROR] [05/22/2012 12:09:12.850] [foo-akka.actor.default-dispatcher-4] [akka://foo/user/$a] error while processing Create()
21a12647-0585-4287-bff8-2afd6686d5f4akka.actor.ActorInitializationException: exception during creation
at akka.actor.ActorCell.create$1(ActorCell.scala:535)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:604)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:215)
at akka.dispatch.Mailbox.run(Mailbox.scala:184)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:574)
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
Caused by: java.lang.Exception: pigdog
at $line3.$read$$iw$$iw$$iw$$iw$Foo.<init>(<console>:10)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at akka.actor.FromClassCreator.apply(Props.scala:188)
at akka.actor.FromClassCreator.apply(Props.scala:187)
at akka.actor.ActorCell.newActor(ActorCell.scala:501)
at akka.actor.ActorCell.create$1(ActorCell.scala:523)
... 8 more

as.actoas.actorOf(Props(new Foo))
res1: akka.actor.ActorRef = Actor[akka://foo/user/$b]

scala> [ERROR] [05/22/2012 12:09:26.255] [foo-akka.actor.default-dispatcher-6] [akka://foo/user/$b] error while processing Create()
518518f4-7429-4ad9-ab9b-fb9e8a5bc05fakka.actor.ActorInitializationException: exception during creation
at akka.actor.ActorCell.create$1(ActorCell.scala:535)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:604)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:215)
at akka.dispatch.Mailbox.run(Mailbox.scala:184)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:574)
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:974)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1478)
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
Caused by: java.lang.Exception: pigdog
at $line3.$read$$iw$$iw$$iw$$iw$Foo.<init>(<console>:10)
at $line5.$read$$iw$$iw$$iw$$iw$$anonfun$1.apply(<console>:13)
at $line5.$read$$iw$$iw$$iw$$iw$$anonfun$1.apply(<console>:13)
at akka.actor.ActorCell.newActor(ActorCell.scala:501)
at akka.actor.ActorCell.create$1(ActorCell.scala:523)
... 8 more

Derek Wyatt

unread,
May 22, 2012, 6:24:59 AM5/22/12
to akka...@googlegroups.com
Wow, this just gets weirder and weirder…

If I put this in a script and run it with "scala" then it fails the way I've said.
If I put in a file, compile it and then run the Main class, it works as expected.
If I try to do it in the REPL as you have, I get:

scala> import akka.actor._
import akka.actor._

scala> val as = ActorSystem("foo")
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'
at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:115)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:137)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:108)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:146)
at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:188)
at akka.actor.ActorSystem$Settings.<init>(ActorSystem.scala:120)
at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:442)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:99)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:85)
at .<init>(<console>:10)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
at java.lang.Thread.run(Thread.java:680)

So… it works… sorta :)
signature.asc

√iktor Ҡlang

unread,
May 22, 2012, 7:46:12 AM5/22/12
to akka...@googlegroups.com
Well that's simply because you do not have your reference.confs sorted out ;-)

Derek Wyatt

unread,
May 22, 2012, 7:50:05 AM5/22/12
to akka...@googlegroups.com
Is this new?  I've never had this problem before… I thought they were all in the jar file?
Does it also explain why it doesn't work when it's in a script, but does work in a compiled class file?
signature.asc

√iktor Ҡlang

unread,
May 22, 2012, 7:52:17 AM5/22/12
to akka...@googlegroups.com
Dude, I have no idea what you're doing.

Cheers,

Derek Wyatt

unread,
May 22, 2012, 8:02:06 AM5/22/12
to akka...@googlegroups.com
Pretty simple:

Compiled program: works, compile then execute Main
---------------------------------
import akka.actor._

class ActorName extends Actor {
  throw new Exception("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
  def receive = { case _ => }
}

object Main {
  def main(args: Array[String]) {
    val sys = ActorSystem("T")
    val a = sys.actorOf(Props(new ActorName))
    val b = sys.actorOf(Props[ActorName])
  }
---------------------------------

Interpreted script: Doesn't work, run with "scala -cp akka-actor.jar script.scala"
---------------------------------
import akka.actor._

class ActorName extends Actor {
  throw new Exception("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
  def receive = { case _ => }
}

val sys = ActorSystem("T")
val a = sys.actorOf(Props(new ActorName))
val b = sys.actorOf(Props[ActorName])
---------------------------------

The last oddity is that the interpreted script can, at least, construct the ActorSystem correctly.  If I run an interactive REPL with the exact same command line args (minus the script, of course) I get the configuration error and can't construct the ActorSystem.

There's a fair bit that's astonishing here.

Regs,
Derek

On 2012-05-22, at 7:46 AM, √iktor Ҡlang wrote:

signature.asc

√iktor Ҡlang

unread,
May 22, 2012, 8:04:37 AM5/22/12
to akka...@googlegroups.com
I wouldn't be surprised if the cp uses a borked classloader that doesn't support decent resource loading.
What happens if you put it on the bootclasspath?

Cheers,

Roland Kuhn

unread,
May 22, 2012, 9:52:57 AM5/22/12
to akka...@googlegroups.com
try -Yrepl-sync …

Roland Kuhn
Typesafe – The software stack for applications that scale.
twitter: @rolandkuhn


Derek Wyatt

unread,
May 22, 2012, 9:54:28 AM5/22/12
to akka...@googlegroups.com
I'll have to try this later... I haven't forgot about it, but I'm screwed for the next 8 hours or so.

Thx Roland / Viktor
D

√iktor Ҡlang

unread,
May 22, 2012, 9:56:45 AM5/22/12
to akka...@googlegroups.com
On Tue, May 22, 2012 at 3:52 PM, Roland Kuhn <goo...@rkuhn.info> wrote:
try -Yrepl-sync …


Yeah, the REPLs classloader is borked, the context classloader is br0ked.

Derek Wyatt

unread,
May 22, 2012, 6:00:09 PM5/22/12
to akka...@googlegroups.com
Ok, so here's the skinny:

- It works just fine when I compile with scalac and all that normal stuff
- The REPL only works with -Yrepl-sync (which dovetails with something that was posted long ago that I now can't recall)
- Nothing I do seems to make the interpreted script work.  I've tried -bootclasspath but it doesn't do squat.

The last point makes me wonder if anyone should ever write a scala script that uses Akka.  I think it should just be avoided.
signature.asc
Reply all
Reply to author
Forward
0 new messages