fix:ReUtil.replaceAll()方法,当replacementTemplate为null对象时,出现空指针异常

This commit is contained in:
LuisStruggle 2022-12-12 19:06:04 +08:00
parent cfc72cc2a9
commit a6ffb7a62f
2 changed files with 13 additions and 0 deletions

View File

@ -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) {

View File

@ -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";