Browse Source

Enhance IpAddressMatcher performance

Closes gh-14493

Signed-off-by: ahmd-nabil <ahm3dnabil99@gmail.com>
ahmd-nabil 1 year ago
parent
commit
a808c139ad

+ 4 - 3
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");
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * you may not use this file except in compliance with the License.
@@ -56,8 +56,9 @@ public final class IpAddressMatcher implements RequestMatcher {
 			this.nMaskBits = -1;
 			this.nMaskBits = -1;
 		}
 		}
 		this.requiredAddress = parseAddress(ipAddress);
 		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
 	@Override