@@ -138,26 +138,28 @@ private static boolean isDeleteMethod(String methodName) {
138
138
* Abstraction of a method on the aggregate root that exposes the events to publish.
139
139
*
140
140
* @author Oliver Gierke
141
+ * @author Mikhail Polivakha
141
142
* @since 1.13
142
143
*/
143
144
static class EventPublishingMethod {
144
145
145
146
private static Map <Class <?>, EventPublishingMethod > cache = new ConcurrentReferenceHashMap <>();
146
147
private static @ SuppressWarnings ("null" ) EventPublishingMethod NONE = new EventPublishingMethod (Object .class , null ,
147
148
null );
148
- private static String ILLEGAL_MODIFCATION = "Aggregate's events were modified during event publication. "
149
- + "Make sure event listeners obtain a fresh instance of the aggregate before adding further events. "
150
- + "Additional events found: %s." ;
149
+ private static final String ILLEGAL_MODIFICATION = "Events of an aggregate '%s' were modified during event publication. "
150
+ + "Make sure event listeners obtain a fresh instance of the aggregate before adding further events. " ;
151
151
152
152
private final Class <?> type ;
153
153
private final Method publishingMethod ;
154
154
private final @ Nullable Method clearingMethod ;
155
+ private final IllegalStateException ILLEGAL_MODIFICATION_EXCEPTION ;
155
156
156
157
EventPublishingMethod (Class <?> type , Method publishingMethod , @ Nullable Method clearingMethod ) {
157
158
158
159
this .type = type ;
159
160
this .publishingMethod = publishingMethod ;
160
161
this .clearingMethod = clearingMethod ;
162
+ this .ILLEGAL_MODIFICATION_EXCEPTION = new IllegalStateException (ILLEGAL_MODIFICATION .formatted (type .getName ()));
161
163
}
162
164
163
165
/**
@@ -216,7 +218,7 @@ public void publishEventsFrom(@Nullable Iterable<?> aggregates, ApplicationEvent
216
218
217
219
postPublication .removeAll (events );
218
220
219
- throw new IllegalStateException ( ILLEGAL_MODIFCATION . formatted ( postPublication )) ;
221
+ throw ILLEGAL_MODIFICATION_EXCEPTION ;
220
222
}
221
223
222
224
if (clearingMethod != null ) {
0 commit comments