1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package org .springframework .web .servlet ;
18
18
19
19
import java .util .ArrayList ;
20
- import java .util .Arrays ;
21
20
import java .util .List ;
22
21
import javax .servlet .http .HttpServletRequest ;
23
22
import javax .servlet .http .HttpServletResponse ;
@@ -80,7 +79,7 @@ public HandlerExecutionChain(Object handler, HandlerInterceptor... interceptors)
80
79
81
80
/**
82
81
* Return the handler object to execute.
83
- * @return the handler object
82
+ * @return the handler object (may be {@code null})
84
83
*/
85
84
public Object getHandler () {
86
85
return this .handler ;
@@ -92,7 +91,7 @@ public void addInterceptor(HandlerInterceptor interceptor) {
92
91
93
92
public void addInterceptors (HandlerInterceptor ... interceptors ) {
94
93
if (!ObjectUtils .isEmpty (interceptors )) {
95
- initInterceptorList (). addAll ( Arrays . asList ( interceptors ));
94
+ CollectionUtils . mergeArrayIntoCollection ( interceptors , initInterceptorList ( ));
96
95
}
97
96
}
98
97
@@ -101,7 +100,7 @@ private List<HandlerInterceptor> initInterceptorList() {
101
100
this .interceptorList = new ArrayList <>();
102
101
if (this .interceptors != null ) {
103
102
// An interceptor array specified through the constructor
104
- this . interceptorList . addAll ( Arrays . asList ( this .interceptors ) );
103
+ CollectionUtils . mergeArrayIntoCollection ( this .interceptors , this . interceptorList );
105
104
}
106
105
}
107
106
this .interceptors = null ;
@@ -202,14 +201,16 @@ void applyAfterConcurrentHandlingStarted(HttpServletRequest request, HttpServlet
202
201
*/
203
202
@ Override
204
203
public String toString () {
205
- if (this .handler == null ) {
204
+ Object handler = getHandler ();
205
+ if (handler == null ) {
206
206
return "HandlerExecutionChain with no handler" ;
207
207
}
208
208
StringBuilder sb = new StringBuilder ();
209
- sb .append ("HandlerExecutionChain with handler [" ).append (this .handler ).append ("]" );
210
- if (!CollectionUtils .isEmpty (this .interceptorList )) {
211
- sb .append (" and " ).append (this .interceptorList .size ()).append (" interceptor" );
212
- if (this .interceptorList .size () > 1 ) {
209
+ sb .append ("HandlerExecutionChain with handler [" ).append (handler ).append ("]" );
210
+ HandlerInterceptor [] interceptors = getInterceptors ();
211
+ if (!ObjectUtils .isEmpty (interceptors )) {
212
+ sb .append (" and " ).append (interceptors .length ).append (" interceptor" );
213
+ if (interceptors .length > 1 ) {
213
214
sb .append ("s" );
214
215
}
215
216
}
0 commit comments