fix:添加判空处理

This commit is contained in:
18855532268
2025-09-18 23:18:15 +08:00
parent 2d5fcc3b08
commit a4f5a084b8
2 changed files with 7 additions and 1 deletions

View File

@@ -104,7 +104,7 @@ public class PinyinUtil {
* @return 汉字返回拼音,非汉字原样返回
*/
public static String getFirstLetter(String str, String separator) {
return getEngine().getFirstLetter(str, separator);
return (str == null) ? null : getEngine().getFirstLetter(str, separator);
}
/**

View File

@@ -22,4 +22,10 @@ public class PinyinUtilTest {
final String result = PinyinUtil.getFirstLetter("崞阳", ", ");
assertEquals("g, y", result);
}
@Test
public void getFirstLetterTest3(){
final String result = PinyinUtil.getFirstLetter(null, ", ");
assertNull(result);
}
}