HandlerExecutionChain prevents re-adding the interceptors array to the list (and declares varargs now)
Issue: SPR-12566
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Handler execution chain, consisting of handler object and any handler interceptors.
|
||||
@@ -45,7 +46,7 @@ public class HandlerExecutionChain {
|
||||
* @param handler the handler object to execute
|
||||
*/
|
||||
public HandlerExecutionChain(Object handler) {
|
||||
this(handler, null);
|
||||
this(handler, (HandlerInterceptor[]) null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +55,7 @@ public class HandlerExecutionChain {
|
||||
* @param interceptors the array of interceptors to apply
|
||||
* (in the given order) before the handler itself executes
|
||||
*/
|
||||
public HandlerExecutionChain(Object handler, HandlerInterceptor[] interceptors) {
|
||||
public HandlerExecutionChain(Object handler, HandlerInterceptor... interceptors) {
|
||||
if (handler instanceof HandlerExecutionChain) {
|
||||
HandlerExecutionChain originalChain = (HandlerExecutionChain) handler;
|
||||
this.handler = originalChain.getHandler();
|
||||
@@ -78,25 +79,25 @@ public class HandlerExecutionChain {
|
||||
}
|
||||
|
||||
public void addInterceptor(HandlerInterceptor interceptor) {
|
||||
initInterceptorList();
|
||||
this.interceptorList.add(interceptor);
|
||||
initInterceptorList().add(interceptor);
|
||||
}
|
||||
|
||||
public void addInterceptors(HandlerInterceptor[] interceptors) {
|
||||
if (interceptors != null) {
|
||||
initInterceptorList();
|
||||
this.interceptorList.addAll(Arrays.asList(interceptors));
|
||||
public void addInterceptors(HandlerInterceptor... interceptors) {
|
||||
if (!ObjectUtils.isEmpty(interceptors)) {
|
||||
initInterceptorList().addAll(Arrays.asList(interceptors));
|
||||
}
|
||||
}
|
||||
|
||||
private void initInterceptorList() {
|
||||
private List<HandlerInterceptor> initInterceptorList() {
|
||||
if (this.interceptorList == null) {
|
||||
this.interceptorList = new ArrayList<HandlerInterceptor>();
|
||||
if (this.interceptors != null) {
|
||||
// An interceptor array specified through the constructor
|
||||
this.interceptorList.addAll(Arrays.asList(this.interceptors));
|
||||
}
|
||||
}
|
||||
if (this.interceptors != null) {
|
||||
this.interceptorList.addAll(Arrays.asList(this.interceptors));
|
||||
this.interceptors = null;
|
||||
}
|
||||
this.interceptors = null;
|
||||
return this.interceptorList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user