[axonframework] Concurrent Modification Exception when creating an AggregateFactory for a subclassed Aggregate.

Hi Leif,

From the stack trace, I am assuming you’re in the process of moving to Axon 3, instead of already being there.
However, line number 79 of the AnnotatedHandlerInspector does not correspond to the latest Axon Framework 3 version, being 3.4.3
Note that you should be able to choose which ever minor version without upgrade problems; only between major release does the framework make massive adjustments, like removal of deprecated functionality.

Regardless of the above, I have a guess why you’re seeing the issue you are seeing.
In Axon 3.0.x we did a quick fix to replace the breaking computeIfAbsent call, which occurs because the AnnotatedHandlerInspector will traverse it’s own implementation during the inspection of its model. This makes it move right back in to the same HashMap, causing the concurrency exception.

Putting that aside, I can suggest a different course of action for registering your Aggregates.
From the shared snippets, I do not see you perform any specifics with the AggregateFactory or aggregate Repository, as you’re simply creating the standard options.

As of Axon 3, you have the possibility to use the AggregateConfigurer class, which has a constructor taking in the class type of the aggregate you want to configure.
Using this approach, you will automatically get all the required components, like the AggregateFactory and Repository, out of the box.

However, you can even simplify this further, as you are on Spring Boot.
Simply annotating the sub-class aggregate with the @Aggregate Spring stereotype annotation will make it so that everything is auto configured for you.
No need to specify the factory and repo yourself, which will simplify your configuration too.

Lastly I want to point out that full aggregate polymorphism, where the framework correctly finds your command handlers all throughout the hierarchy, is a pending feature for Axon 4.3 (which you can find here).

Hope this sheds some light on your situation Leif!

Cheers,
Steven