diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e255206f..2d3039357 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ * 【core 】 修复JavaSourceCompiler.addSource目录处理错误问题(issue#3425@Github) * 【core 】 修复时间戳转Bean时异常问题(issue#I8NMP7@Gitee) * 【core 】 修复PostgreSQL使用upsert字段大小写问题问题(issue#I8PB4X@Gitee) +* 【extra 】 修复TinyPinyinEngine可能的空指针问题(issue#3437@Github) ------------------------------------------------------------------------------------------------------------- # 5.8.23(2023-11-12) diff --git a/hutool-extra/src/main/java/cn/hutool/extra/pinyin/engine/tinypinyin/TinyPinyinEngine.java b/hutool-extra/src/main/java/cn/hutool/extra/pinyin/engine/tinypinyin/TinyPinyinEngine.java index edc678cae..2ecf0dd1c 100644 --- a/hutool-extra/src/main/java/cn/hutool/extra/pinyin/engine/tinypinyin/TinyPinyinEngine.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/pinyin/engine/tinypinyin/TinyPinyinEngine.java @@ -1,5 +1,7 @@ package cn.hutool.extra.pinyin.engine.tinypinyin; +import cn.hutool.core.lang.Opt; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.pinyin.PinyinEngine; import com.github.promeg.pinyinhelper.Pinyin; @@ -51,7 +53,8 @@ public class TinyPinyinEngine implements PinyinEngine { @Override public String getPinyin(String str, String separator) { - return Pinyin.toPinyin(str, separator).toLowerCase(); + final String pinyin = Pinyin.toPinyin(str, separator); + return StrUtil.isEmpty(pinyin) ? pinyin : pinyin.toLowerCase(); } }