From 99ec3bbeb4a5cf0fa49269cfe1b64c7f7d73bf17 Mon Sep 17 00:00:00 2001 From: Looly Date: Wed, 20 Dec 2023 21:10:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DTinyPinyinEngine=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E7=9A=84=E7=A9=BA=E6=8C=87=E9=92=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../extra/pinyin/engine/tinypinyin/TinyPinyinEngine.java | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e255206f2..2d3039357b 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 edc678cae3..2ecf0dd1cb 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 String getPinyin(char c) { @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(); } }