regression of Creator check, #20537 (#20538)

* try to reproduce the regression of Creator check, #20537

* fix regression of Creator check, #20537

* the check of the enclosing class parameter should check the first parameter
This commit is contained in:
Patrik Nordwall 2016-05-24 13:10:23 +02:00 committed by Konrad Malawski
parent f46be728e8
commit b3591b48d0
2 changed files with 42 additions and 1 deletions

View file

@ -5,6 +5,10 @@
package akka.actor;
import static org.junit.Assert.*;
import static java.util.stream.Collectors.toCollection;
import java.util.ArrayList;
import java.util.stream.IntStream;
import akka.testkit.TestActors;
import org.junit.Test;
@ -144,6 +148,30 @@ public class ActorCreationTest extends JUnitSuite {
}
}
public static class Issue20537Reproducer extends UntypedActor {
static final class ReproducerCreator implements Creator<Issue20537Reproducer> {
final boolean create;
private ReproducerCreator(boolean create) {
this.create = create;
}
@Override
public Issue20537Reproducer create() throws Exception {
return new Issue20537Reproducer(create);
}
}
public Issue20537Reproducer(boolean create) {
}
@Override
public void onReceive(Object message) throws Exception {
}
}
@Test
public void testWrongAnonymousInPlaceCreator() {
try {
@ -287,5 +315,18 @@ public class ActorCreationTest extends JUnitSuite {
assertEquals(UntypedTestActor.class, p.actorClass());
}
@Test
public void testIssue20537Reproducer() {
final Issue20537Reproducer.ReproducerCreator creator = new Issue20537Reproducer.ReproducerCreator(false);
final Props p = Props.create(creator);
assertEquals(Issue20537Reproducer.class, p.actorClass());
ArrayList<Props> pList = IntStream.range(0, 4).mapToObj(i -> Props.create(creator))
.collect(toCollection(ArrayList::new));
for (Props each : pList) {
assertEquals(Issue20537Reproducer.class, each.actorClass());
}
}
}

View file

@ -87,7 +87,7 @@ private[akka] trait AbstractProps {
if (i == declaredConstructors.length) false
else {
val c = declaredConstructors(i)
if (c.getParameterCount >= 1 && c.getParameterTypes()(i) == enclosingClass)
if (c.getParameterCount >= 1 && c.getParameterTypes()(0) == enclosingClass)
true
else
loop(i + 1) // recur