DATACMNS-1163 - EventPublishingInterceptor now prefers arguments over return values for event publication.
We now prefer to inspect the arguments handed to save(…) methods over inspecting the return value as the invocation of the actual method is free to exchange the instance handed into it and return a completely new one with the events contained in the parameter completely wiped.
This commit is contained in:
@@ -91,13 +91,16 @@ public class EventPublishingRepositoryProxyPostProcessor implements RepositoryPr
|
||||
@Override
|
||||
public Object invoke(@SuppressWarnings("null") MethodInvocation invocation) throws Throwable {
|
||||
|
||||
Object[] arguments = invocation.getArguments();
|
||||
Object result = invocation.proceed();
|
||||
|
||||
if (!invocation.getMethod().getName().startsWith("save")) {
|
||||
return result;
|
||||
}
|
||||
|
||||
eventMethod.publishEventsFrom(result, publisher);
|
||||
Object eventSource = arguments.length == 1 ? arguments[0] : result;
|
||||
|
||||
eventMethod.publishEventsFrom(eventSource, publisher);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user