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:
Oliver Gierke
2017-09-20 11:09:25 +02:00
parent a8cc4783bf
commit 72b927ea2c
2 changed files with 27 additions and 3 deletions

View File

@@ -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;
}