Skip to content

Commit 92f18a4

Browse files
committed
HandlerExecutionChain.toString() includes reliable interceptor number
Issue: SPR-15525
1 parent 25aef4d commit 92f18a4

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717
package org.springframework.web.servlet;
1818

1919
import java.util.ArrayList;
20-
import java.util.Arrays;
2120
import java.util.List;
2221
import javax.servlet.http.HttpServletRequest;
2322
import javax.servlet.http.HttpServletResponse;
@@ -80,7 +79,7 @@ public HandlerExecutionChain(Object handler, HandlerInterceptor... interceptors)
8079

8180
/**
8281
* Return the handler object to execute.
83-
* @return the handler object
82+
* @return the handler object (may be {@code null})
8483
*/
8584
public Object getHandler() {
8685
return this.handler;
@@ -92,7 +91,7 @@ public void addInterceptor(HandlerInterceptor interceptor) {
9291

9392
public void addInterceptors(HandlerInterceptor... interceptors) {
9493
if (!ObjectUtils.isEmpty(interceptors)) {
95-
initInterceptorList().addAll(Arrays.asList(interceptors));
94+
CollectionUtils.mergeArrayIntoCollection(interceptors, initInterceptorList());
9695
}
9796
}
9897

@@ -101,7 +100,7 @@ private List<HandlerInterceptor> initInterceptorList() {
101100
this.interceptorList = new ArrayList<>();
102101
if (this.interceptors != null) {
103102
// An interceptor array specified through the constructor
104-
this.interceptorList.addAll(Arrays.asList(this.interceptors));
103+
CollectionUtils.mergeArrayIntoCollection(this.interceptors, this.interceptorList);
105104
}
106105
}
107106
this.interceptors = null;
@@ -202,14 +201,16 @@ void applyAfterConcurrentHandlingStarted(HttpServletRequest request, HttpServlet
202201
*/
203202
@Override
204203
public String toString() {
205-
if (this.handler == null) {
204+
Object handler = getHandler();
205+
if (handler == null) {
206206
return "HandlerExecutionChain with no handler";
207207
}
208208
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) {
213214
sb.append("s");
214215
}
215216
}

0 commit comments

Comments
 (0)