From 92f18a4985f2eb66551883a77aba5e38a6ddd0a0 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 7 May 2017 21:05:16 +0200 Subject: [PATCH] HandlerExecutionChain.toString() includes reliable interceptor number Issue: SPR-15525 --- .../web/servlet/HandlerExecutionChain.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java index 073d55d6768..4b7d82ad6e8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -17,7 +17,6 @@ package org.springframework.web.servlet; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -80,7 +79,7 @@ public class HandlerExecutionChain { /** * Return the handler object to execute. - * @return the handler object + * @return the handler object (may be {@code null}) */ public Object getHandler() { return this.handler; @@ -92,7 +91,7 @@ public class HandlerExecutionChain { public void addInterceptors(HandlerInterceptor... interceptors) { if (!ObjectUtils.isEmpty(interceptors)) { - initInterceptorList().addAll(Arrays.asList(interceptors)); + CollectionUtils.mergeArrayIntoCollection(interceptors, initInterceptorList()); } } @@ -101,7 +100,7 @@ public class HandlerExecutionChain { this.interceptorList = new ArrayList<>(); if (this.interceptors != null) { // An interceptor array specified through the constructor - this.interceptorList.addAll(Arrays.asList(this.interceptors)); + CollectionUtils.mergeArrayIntoCollection(this.interceptors, this.interceptorList); } } this.interceptors = null; @@ -202,14 +201,16 @@ public class HandlerExecutionChain { */ @Override public String toString() { - if (this.handler == null) { + Object handler = getHandler(); + if (handler == null) { return "HandlerExecutionChain with no handler"; } StringBuilder sb = new StringBuilder(); - sb.append("HandlerExecutionChain with handler [").append(this.handler).append("]"); - if (!CollectionUtils.isEmpty(this.interceptorList)) { - sb.append(" and ").append(this.interceptorList.size()).append(" interceptor"); - if (this.interceptorList.size() > 1) { + sb.append("HandlerExecutionChain with handler [").append(handler).append("]"); + HandlerInterceptor[] interceptors = getInterceptors(); + if (!ObjectUtils.isEmpty(interceptors)) { + sb.append(" and ").append(interceptors.length).append(" interceptor"); + if (interceptors.length > 1) { sb.append("s"); } }