From 7ae5a895aef8df15dc2b5ad87d9d24fcda54287e Mon Sep 17 00:00:00 2001 From: ahmd-nabil Date: Sat, 27 Jan 2024 01:02:11 +0200 Subject: [PATCH] Enhance IpAddressMatcher performance Closes gh-14493 Signed-off-by: ahmd-nabil --- .../security/web/util/matcher/IpAddressMatcher.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/src/main/java/org/springframework/security/web/util/matcher/IpAddressMatcher.java b/web/src/main/java/org/springframework/security/web/util/matcher/IpAddressMatcher.java index 3be7851094d..7df1aaa3e4c 100644 --- a/web/src/main/java/org/springframework/security/web/util/matcher/IpAddressMatcher.java +++ b/web/src/main/java/org/springframework/security/web/util/matcher/IpAddressMatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -56,8 +56,9 @@ public IpAddressMatcher(String ipAddress) { this.nMaskBits = -1; } this.requiredAddress = parseAddress(ipAddress); - Assert.isTrue(this.requiredAddress.getAddress().length * 8 >= this.nMaskBits, - String.format("IP address %s is too short for bitmask of length %d", ipAddress, this.nMaskBits)); + String finalIpAddress = ipAddress; + Assert.isTrue(this.requiredAddress.getAddress().length * 8 >= this.nMaskBits, () -> String + .format("IP address %s is too short for bitmask of length %d", finalIpAddress, this.nMaskBits)); } @Override