Home » Java » java – Why Spring HandlerExecutionChain has both interceptors and interceptorList?-Exceptionshub

java – Why Spring HandlerExecutionChain has both interceptors and interceptorList?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

Why there are array type interceptors and list type interceptorList in spring source org.springframework.web.servlet.HandlerExecutionChain? Is this necessary?

public class HandlerExecutionChain {

    private final Object handler;

    @Nullable
    private HandlerInterceptor[] interceptors;

    @Nullable
    private List<HandlerInterceptor> interceptorList;

    .....
}
How to&Answers:

When you look in the source code you will see that only HandlerInterceptor[] interceptors is only returned outside the HandlerExecutionChain in:

public HandlerInterceptor[] getInterceptors() {

Also you can look at List<HandlerInterceptor> initInterceptorList( that is used to create List<HandlerInterceptor> interceptorList. It looks like the interceptorList is collection that helps in creating the interceptors array that later is exposing outside.