mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix:ReUtil.replaceAll()方法,当replacementTemplate为null对象时,出现空指针异常
This commit is contained in:
parent
cfc72cc2a9
commit
a6ffb7a62f
@ -876,6 +876,9 @@ public class ReUtil {
|
||||
return StrUtil.str(content);
|
||||
}
|
||||
|
||||
// replacementTemplate字段不能为null,否则无法抉择如何处理结果
|
||||
Assert.notNull(replacementTemplate, "ReplacementTemplate must be not null !");
|
||||
|
||||
final Matcher matcher = pattern.matcher(content);
|
||||
boolean result = matcher.find();
|
||||
if (result) {
|
||||
|
@ -115,6 +115,16 @@ public class ReUtilTest {
|
||||
Assert.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceAllTest3() {
|
||||
// 修改前:ReUtil.replaceAll()方法,当replacementTemplate为null对象时,出现空指针异常
|
||||
final String str = null;
|
||||
// Assert.assertThrows(NullPointerException.class, () -> ReUtil.replaceAll(content, "(\\d+)", str));
|
||||
|
||||
// 修改后:判断ReUtil.replaceAll()方法,当replacementTemplate为null对象时,提示为非法的参数异常:ReplacementTemplate must be not null !
|
||||
Assert.assertThrows(IllegalArgumentException.class, () -> ReUtil.replaceAll(content, "(\\d+)", str));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceTest() {
|
||||
final String str = "AAABBCCCBBDDDBB";
|
||||
|
Loading…
x
Reference in New Issue
Block a user