2.0-RC1: foo is not assignable from class bar

462 views
Skip to first unread message

G J

unread,
Feb 14, 2012, 3:42:06 PM2/14/12
to Akka User List
A simple akka test programs in 2.0-RC1 now generate an error:
interface foobar is not assignable from class foobaz.

This did not occur in earlier versions, and appears to be restricted
to the interactive loop. The test program runs fine under sbt.

What gives? What do I need to do to continue running in the REPL?

Appreciated.

√iktor Ҡlang

unread,
Feb 14, 2012, 3:51:45 PM2/14/12
to akka...@googlegroups.com

Akka uses the context classloader of the thread that creates the actor system. Try to set it to null before.

Cheers,
V

--
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.

Jonas Bonér

unread,
Feb 14, 2012, 3:53:39 PM2/14/12
to akka...@googlegroups.com

Could you post the simple program? It could assist us understanding the question.

--
Jonas Bonér
CTO
Typesafe - The software stack for applications that scale
Phone: +46 733 777 123
Twitter: @jboner
Blog: letitcrash.com

On Feb 14, 2012 9:42 PM, "G J" <oda...@gmail.com> wrote:

G J

unread,
Feb 14, 2012, 4:22:08 PM2/14/12
to Akka User List
A trivial test program is pasted below.

In sbt, execute compile and then run. Under the REPL if you import and
try and run Test.jolly, you should get the error:

java.lang.ClassCastException: interface akka.actor.ActorRefProvider is
not assignable from class akka.actor.LocalActorRefProvider

Thanks.

[Plz. Not class hakkery again...]
---------------------------------------------------
package test.akka

import akka.actor
import akka.util.duration._

object Test extends App {
class Jolly extends actor.Actor {
def receive = {
case "start" =>
context.setReceiveTimeout(5 * 1000 milliseconds)
case actor.ReceiveTimeout =>
println("Jolly good> timeout")
}
}

def jolly {
val system = actor.ActorSystem("Jolly")
val toll = system.actorOf(actor.Props[Jolly], name = "jolly")
toll ! "start"
}

override def main(args: Array[String]) = jolly

Peter Vlugter

unread,
Feb 14, 2012, 9:04:13 PM2/14/12
to akka...@googlegroups.com
I had no problems with running this in a test project. Here's the output I see:

sbt> run
[info] Running test.akka.Test
Jolly good> timeout
Jolly good> timeout
Jolly good> timeout

sbt> console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import test.akka.Test
import test.akka.Test

scala> Test.jolly

scala> Jolly good> timeout
Jolly good> timeout
Jolly good> timeout
...

G J

unread,
Feb 14, 2012, 10:49:37 PM2/14/12
to Akka User List
Interesting indeed.

It runs fine for me too when I run it under the console through sbt
the way you describe. However, if I run it using:

scala -classpath <path to classes and jar>

and import and execute, I do get the error I mentioned.

Why does running scala directly yield the error...?

Thanks.

Peter Vlugter

unread,
Feb 14, 2012, 11:21:58 PM2/14/12
to akka...@googlegroups.com

On 15/02/2012, at 4:49 PM, G J wrote:

> Interesting indeed.
>
> It runs fine for me too when I run it under the console through sbt
> the way you describe. However, if I run it using:
>
> scala -classpath <path to classes and jar>
>
> and import and execute, I do get the error I mentioned.
>
> Why does running scala directly yield the error...?

Each line in the repl runs in a separate thread. If you add the -Yrepl-sync option it should work fine.

You could also set the context classloader with something like:

{ Thread.currentThread.setContextClassLoader(Test.getClass.getClassLoader); Test.jolly }

Mike Slinn

unread,
Feb 15, 2012, 1:19:32 AM2/15/12
to akka...@googlegroups.com
Where is -Yrepl-sync documented?

Mike

Peter Vlugter

unread,
Feb 15, 2012, 2:44:52 AM2/15/12
to akka...@googlegroups.com

On 15/02/2012, at 7:19 PM, Mike Slinn wrote:

> Where is -Yrepl-sync documented?

I don't know if there's richer documentation but scala -Y lists all the -Y options with short descriptions.

G J

unread,
Feb 15, 2012, 6:02:11 AM2/15/12
to Akka User List
Yes. Both those suggestions made it work, yet I fail to understand
what the class loader has to do with it. For that matter, I would
never have guessed to look at repl-sync either.

Would highly appreciated a brief explanation.

Thanks.

√iktor Ҡlang

unread,
Feb 15, 2012, 9:19:55 AM2/15/12
to akka...@googlegroups.com
Akka uses the context class loader from the thread that created the ActorSystem, and since every line is on it's own loader, you¨ll have ap roblem if you don¨t use that.

We should document it. Open a ticket.


Thanks!

Cheers,


--
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.




--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

Reply all
Reply to author
Forward
0 new messages