Bug in Contact from axon-addressbook-app?

I wonder if there is a bug in the Contact class from the axon-
addressbook-app example:

1) Method already removes the address:

public void removeAddress(AddressType type) {
    if (addresses.remove(type) != null) {
        apply(new AddressRemovedEvent(type));
    }
}

2) Event handler method does the same again:

@EventHandler
protected void handleAddressRemovedEvent(AddressRemovedEvent event) {
    addresses.remove(event.getType());
}

I thought the first type of aggregate root method should only checks
constraints and the second applies the change!? So the first method
should be something like this:

public void removeAddress(AddressType type) {
    if (addresses.containsKey(type)) {
        apply(new AddressRemovedEvent(type));
    }
}

Hi Michael,

well spotted. It is indeed a bug (though one unlikely to have negative side-effects), and the code you provided is the correct way to do it.

Cheers,

Allard

It took a while, but this is fixed now. Thanks for pointing this out