Skip to content

Commit

Permalink
Fixed issue with a wrong cast to Collection
Browse files Browse the repository at this point in the history
Resolves issue #461
  • Loading branch information
abuijze committed Dec 20, 2017
1 parent 0f3f37f commit b15a27a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
Expand Up @@ -25,7 +25,6 @@
import org.axonframework.eventhandling.EventMessage; import org.axonframework.eventhandling.EventMessage;


import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Stream; import java.util.stream.Stream;
Expand Down Expand Up @@ -86,7 +85,9 @@ protected <T> Stream<Object> resolveEventTargets(EventMessage message,
T parentEntity, T parentEntity,
Field field, Field field,
ForwardingMode eventForwardingMode) { ForwardingMode eventForwardingMode) {
Collection<Object> fieldValue = ReflectionUtils.getFieldValue(field, parentEntity); Iterable<Object> fieldValue = ReflectionUtils.getFieldValue(field, parentEntity);
return fieldValue == null ? Stream.empty() : eventForwardingMode.filterCandidates(message, fieldValue.stream()); return fieldValue == null
? Stream.empty()
: eventForwardingMode.filterCandidates(message, StreamSupport.stream(fieldValue.spliterator(), false));
} }
} }
Expand Up @@ -35,6 +35,7 @@
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;


import static org.axonframework.commandhandling.GenericCommandMessage.asCommandMessage; import static org.axonframework.commandhandling.GenericCommandMessage.asCommandMessage;
Expand Down Expand Up @@ -330,13 +331,13 @@ private static class SomeRecursiveEntity {
private final String entityId; private final String entityId;


@AggregateMember @AggregateMember
private final Collection<SomeRecursiveEntity> children; private final SomeIterable<SomeRecursiveEntity> children;


public SomeRecursiveEntity(Supplier<Collection<SomeRecursiveEntity>> supplier, SomeRecursiveEntity parent, String entityId) { public SomeRecursiveEntity(Supplier<Collection<SomeRecursiveEntity>> supplier, SomeRecursiveEntity parent, String entityId) {
this.supplier = supplier; this.supplier = supplier;
this.parent = parent; this.parent = parent;
this.entityId = entityId; this.entityId = entityId;
this.children = supplier.get(); this.children = new SomeIterable<>(supplier.get());
} }


public SomeRecursiveEntity getChild(String childId) { public SomeRecursiveEntity getChild(String childId) {
Expand Down Expand Up @@ -419,4 +420,46 @@ public String getId() {
return id; return id;
} }
} }

/**
* Wrapper implementation to ensure that the @AggregateMember field is solely triggered by the fact it implements
* Iterable, and doesn't depend on any other interface being declared. See issue #461.
*
* @param <T> The type contained in this iterable
*/
private static class SomeIterable<T> implements Iterable<T> {

private final Collection<T> contents;

public SomeIterable(Collection<T> contents) {
this.contents = contents;
}

@Override
public Iterator<T> iterator() {
return contents.iterator();
}

@Override
public void forEach(Consumer<? super T> action) {
contents.forEach(action);
}

@Override
public Spliterator<T> spliterator() {
return contents.spliterator();
}

public boolean add(T item) {
return contents.add(item);
}

public boolean remove(T item) {
return contents.remove(item);
}

public int size() {
return contents.size();
}
}
} }

0 comments on commit b15a27a

Please sign in to comment.