New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ExposeInvocationInterceptor doesn't make a best effort to be first in execution order [SPR-12351] #16956
Comments
Juergen Hoeller commented As of 4.1.2, ExposeInvocationInterceptor declares itself as PriorityOrdered now. An option for another interceptor to override with PriorityOrdered and HIGHEST_PRECEDENCE is still left as an escape hatch; note that no regular interceptor will ever implemented PriorityOrdered, so this should be alright. Juergen |
This bug still exists. The fix not take affect. My SpringBoot version is 5.2.9. Question in stackoverflow describe the issue. Can we recheck the problem? |
I can confirm that this is still a problem, e.g. in this situation where @Aspect
@Component
@Order(value = 1)
public class PollableStreamListenerAspect {
private final ExecutorService executor = Executors.newFixedThreadPool(1);
private volatile boolean paused = false;
@Around("@annotation(de.scrum_master.spring.q67155048.PollableStreamListener)")
public void receiveMessage(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("Receiving message");
if (!paused) {
// The separate thread is not busy with a previous message, so process this message:
Runnable runnable = () -> {
try {
paused = true;
joinPoint.proceed();
}
catch (Throwable throwable) {
throwable.printStackTrace();
}
finally {
paused = false;
}
};
executor.submit(runnable);
}
else {
System.out.println("Re-queue");
}
}
} Without the |
Update to my previous comment: This workaround breaks as soon as the aspect advice binds parameters via
This can be avoided by using a precedence value other than Update: Again, please see my updated StackOverflow answer for a complete sample application. Just copy the variant of application files and aspects you need in order to reproduce both problems and also my workaround, using manual parameter binding via P.S.: The aspect implementing |
Juan Martin Sotuyo Dodero opened SPR-12351 and commented
ExposeInvocationInterceptor, which is automatically added to the chain when using an AspectJ aspect, should run first, but doesn't make enough efforts to do so. If this does not occur, an exception will be thrown at runtime saying not all parameters could be bound (which may be misleading to the developer, since the number of arguments being match does not coincide with those he set in the advice; and no reference to ExposeInvocationInterceptor is ever made; not even on the official documentation http://docs.spring.io/spring/docs/4.1.x/spring-framework-reference/html/aop.html#aop-ataspectj-advice-ordering )
First of all, it's implementation of
@Ordered
doesn't set Ordered.HIGHEST_PRECEDENCE, but Ordered.HIGHEST_PRECEDENCE + 1 (which, since a lower value is translated into higher precedence, means "second").Also of note, is that even setting it to Ordered.HIGHEST_PRECEDENCE would not guarantee it to run first when the other aspect has Ordered.HIGHEST_PRECEDENCE. This could be attoned by using PriorityOrdered instead of Ordered in ExposeInvocationInterceptor. Doing so would guarantee the interceptor runs first to every other aspect, except maybe those that also are PriorityOrdered with Ordered.HIGHEST_PRECEDENCE.
Affects: 4.1.1
Referenced from: commits fb08644
The text was updated successfully, but these errors were encountered: