diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java index ead36e33c1..658f4ba0f3 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java @@ -420,6 +420,7 @@ public abstract class AbstractMethodMessageHandler *

If there are no matching prefixes, return {@code null}. *

If there are no destination prefixes, return the destination as is. */ + @SuppressWarnings("ForLoopReplaceableByForEach") @Nullable protected String getLookupDestination(@Nullable String destination) { if (destination == null) { @@ -428,8 +429,7 @@ public abstract class AbstractMethodMessageHandler if (CollectionUtils.isEmpty(this.destinationPrefixes)) { return destination; } - // Avoid unnecessary iterator allocation - for (int i = 0, size = this.destinationPrefixes.size(); i < size; i++) { + for (int i = 0; i < this.destinationPrefixes.size(); i++) { String prefix = this.destinationPrefixes.get(i); if (destination.startsWith(prefix)) { return destination.substring(prefix.length()); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java index c019167daa..ebc9d204a8 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandlerComposite.java @@ -1,5 +1,6 @@ /* - * Copyright 2002-2017 the original author or authors. +/* + * Copyright 2002-2018 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. @@ -81,10 +82,10 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet return getReturnValueHandler(returnType) != null; } + @SuppressWarnings("ForLoopReplaceableByForEach") @Nullable private HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) { - // Avoid allocating an iterator - for (int i = 0, size = this.returnValueHandlers.size(); i < size; i++) { + for (int i = 0; i < this.returnValueHandlers.size(); i++) { HandlerMethodReturnValueHandler handler = this.returnValueHandlers.get(i); if (handler.supportsReturnType(returnType)) { return handler;