Merge pull request #1545 from akka/wip-3438-unbogusify-check-constructors-√

#3438 - Adding support for non-static top-level classes in check constr...
This commit is contained in:
Roland Kuhn 2013-06-20 04:55:04 -07:00
commit 511393d9a3
3 changed files with 17 additions and 1 deletions

View file

@ -60,6 +60,12 @@ public class ActorCreationTest {
final Props p = Props.create(new C());
assertEquals(UntypedActor.class, p.actorClass());
}
@Test
public void testTopLevelNonStaticCreator() {
final Props p = Props.create(new NonStaticCreator());
assertEquals(UntypedActor.class, p.actorClass());
}
@Test
public void testParametricCreator() {

View file

@ -0,0 +1,10 @@
package akka.actor;
import akka.japi.Creator;
public class NonStaticCreator implements Creator<UntypedActor> {
@Override
public UntypedActor create() throws Exception {
return null;
}
}

View file

@ -123,7 +123,7 @@ object Props {
* Create new Props from the given [[Creator]].
*/
def create[T <: Actor](creator: Creator[T]): Props = {
if ((creator.getClass.getModifiers & Modifier.STATIC) == 0)
if ((creator.getClass.getEnclosingClass ne null) && (creator.getClass.getModifiers & Modifier.STATIC) == 0)
throw new IllegalArgumentException("cannot use non-static local Creator to create actors; make it static or top-level")
val ac = classOf[Actor]
val actorClass = Reflect.findMarker(creator.getClass, classOf[Creator[_]]) match {