}
}
private void detectIllegalStateChanges() {
if (aggregateIdentifier != null && workingAggregate != null && reportIllegalStateChange) {
UnitOfWork uow = DefaultUnitOfWork.startAndGet();
try {
EventSourcedAggregateRoot aggregate2 = repository.load(aggregateIdentifier);
if (workingAggregate.isDeleted()) {
throw new AxonAssertionError("The working aggregate was considered deleted, "
+ "but the Repository still contains a non-deleted copy of "
+ "the aggregate. Make sure the aggregate explicitly marks "
+ "itself as deleted in an EventHandler.");
}
assertValidWorkingAggregateState(aggregate2);
} catch (AggregateNotFoundException notFound) {
if (!workingAggregate.isDeleted()) {
throw new AxonAssertionError("The working aggregate was not considered deleted, " //NOSONAR
+ "but the Repository cannot recover the state of the "
+ "aggregate, as it is considered deleted there.");
}
} catch (RuntimeException e) {
logger.warn("An Exception occurred while detecting illegal state changes in {}.",
workingAggregate.getClass().getName(),
e);
} finally {
// rollback to prevent changes bing pushed to event store
uow.rollback();
}
}
}