From 2afcf605660f4f967e03b6ce1d5753fb2d96245c Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 4 Nov 2022 16:44:59 +0100 Subject: [PATCH] Avoid String allocations with Assert.state() --- .../messaging/rsocket/service/RSocketServiceMethod.java | 3 ++- .../springframework/web/service/invoker/HttpServiceMethod.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java index 57b4f8daba..29b0c796e9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java @@ -229,7 +229,8 @@ final class RSocketServiceMethod { break; } } - Assert.state(resolved, formatArgumentError(this.parameters[i], "No suitable resolver")); + int index = i; + Assert.state(resolved, () -> formatArgumentError(this.parameters[index], "No suitable resolver")); } } diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java index 438a82980e..b0095c0028 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java @@ -116,7 +116,8 @@ final class HttpServiceMethod { break; } } - Assert.state(resolved, formatArgumentError(this.parameters[i], "No suitable resolver")); + int index = i; + Assert.state(resolved, () -> formatArgumentError(this.parameters[index], "No suitable resolver")); } }