From 5a91443e36a242d26f4af1911b71cdccb4e3719d Mon Sep 17 00:00:00 2001 From: Looly Date: Sat, 6 Aug 2022 18:51:28 +0800 Subject: [PATCH] fix bug --- CHANGELOG.md | 3 ++- hutool-core/src/main/java/cn/hutool/core/util/RandomUtil.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f09f29030..d0dcede5d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,12 @@ ------------------------------------------------------------------------------------------------------------- -# 5.8.6.M1 (2022-07-30) +# 5.8.6.M1 (2022-08-06) ### 🐣新特性 ### 🐞Bug修复 * 【http 】 修复https下可能的Patch、Get请求失效问题(issue#I3Z3DH@Gitee) +* 【core 】 修复RandomUtil#randomString 入参length为负数时报错问题(issue#2515@Github) ------------------------------------------------------------------------------------------------------------- diff --git a/hutool-core/src/main/java/cn/hutool/core/util/RandomUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/RandomUtil.java index 2c415b386..0a7ec302c 100755 --- a/hutool-core/src/main/java/cn/hutool/core/util/RandomUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/RandomUtil.java @@ -549,11 +549,11 @@ public class RandomUtil { if (StrUtil.isEmpty(baseString)) { return StrUtil.EMPTY; } - final StringBuilder sb = new StringBuilder(length); - if (length < 1) { length = 1; } + + final StringBuilder sb = new StringBuilder(length); int baseLength = baseString.length(); for (int i = 0; i < length; i++) { int number = randomInt(baseLength);