#2217 - setting accessible = true before newInstance

This commit is contained in:
Viktor Klang 2012-06-13 12:23:02 +02:00
parent 8d12385a3e
commit 8ce6ac3e3e
3 changed files with 34 additions and 1 deletions

View file

@ -0,0 +1,22 @@
package akka.actor;
import com.sun.xml.internal.ws.api.PropertySet;
/**
* Created by IntelliJ IDEA.
* User: viktorklang
* Date: 6/13/12
* Time: 12:12 PM
* To change this template use File | Settings | File Templates.
*/
public class NonPublicClass {
public static Props createProps() {
return new Props(MyNonPublicActorClass.class);
}
}
class MyNonPublicActorClass extends UntypedActor {
@Override public void onReceive(Object msg) {
getSender().tell(msg);
}
}

View file

@ -358,6 +358,13 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
system.stop(serverRef) system.stop(serverRef)
} }
"support actorOfs where the class of the actor isn't public" in {
val a = system.actorOf(NonPublicClass.createProps())
a.tell("pigdog", testActor)
expectMsg("pigdog")
system stop a
}
"stop when sent a poison pill" in { "stop when sent a poison pill" in {
val timeout = Timeout(20000) val timeout = Timeout(20000)
val ref = system.actorOf(Props(new Actor { val ref = system.actorOf(Props(new Actor {

View file

@ -186,5 +186,9 @@ case class Props(
* able to optimize serialization. * able to optimize serialization.
*/ */
private[akka] case class FromClassCreator(clazz: Class[_ <: Actor]) extends Function0[Actor] { private[akka] case class FromClassCreator(clazz: Class[_ <: Actor]) extends Function0[Actor] {
def apply(): Actor = clazz.newInstance def apply(): Actor = {
val ctor = clazz.getDeclaredConstructor()
ctor.setAccessible(true)
ctor.newInstance()
}
} }